Created
March 17, 2018 09:18
-
-
Save Exerosis/79e977046831147bf696fb5a4ea9b91c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static final Field VEHICLE; | |
| private static final Field PASSENGERS; | |
| static { | |
| Field vehicle = null, passengers = null; | |
| for (Field field : PacketPlayOutMount.class.getDeclaredFields()) { | |
| if (field.getType() == int.class) { | |
| field.setAccessible(true); | |
| vehicle = field; | |
| } else if (field.getType() == int[].class) { | |
| field.setAccessible(true); | |
| passengers = field; | |
| } | |
| } | |
| VEHICLE = vehicle; | |
| PASSENGERS = passengers; | |
| } | |
| public static Packet getMountPacket(int vehicle, int... passengers) { | |
| try { | |
| PacketPlayOutMount packet = new PacketPlayOutMount(); | |
| VEHICLE.set(packet, vehicle); | |
| PASSENGERS.set(packet, passengers); | |
| return packet; | |
| } catch (IllegalAccessException e) { | |
| throw new RuntimeException(e); | |
| } | |
| } | |
| public static List<Packet> setNameTag(Entity entity, String... lines) { | |
| net.minecraft.server.v1_12_R1.World world = ((CraftWorld) entity.getWorld()).getHandle(); | |
| int[] passengers = new int[lines.length]; | |
| List<Packet> packets = new LinkedList<>(); | |
| for (int i = 0; i < lines.length; i++) { | |
| int size = (i - 1) * -1; | |
| EntitySlime holder = new EntitySlime(world); | |
| holder.setInvulnerable(true); | |
| Location location = entity.getLocation(); | |
| holder.setPosition(location.getX(), location.getY(), location.getZ()); | |
| holder.setInvisible(true); | |
| holder.setSize(size, false); | |
| EntityArmorStand line = new EntityArmorStand(world); | |
| line.setInvulnerable(true); | |
| line.setPosition(location.getX(), location.getY(), location.getZ()); | |
| line.setInvisible(true); | |
| line.setSmall(true); | |
| line.setCustomName(lines[i]); | |
| line.setCustomNameVisible(true); | |
| passengers[i] = holder.getId(); | |
| packets.add(new PacketPlayOutSpawnEntityLiving(holder)); | |
| packets.add(new PacketPlayOutSpawnEntityLiving(line)); | |
| packets.add(getMountPacket(holder.getId(), line.getId())); | |
| } | |
| packets.add(getMountPacket(entity.getEntityId(), passengers)); | |
| return packets; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment