diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java index eda598747..68fdf028b 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_13Types.java @@ -6,7 +6,7 @@ import lombok.Getter; import us.myles.ViaVersion.api.Via; -// todo 18w10d +// TODO auto generate 18w11a with PAaaS public class Entity1_13Types { public static EntityType getTypeFromId(int typeID, boolean isObject) { Optional type; @@ -191,33 +191,33 @@ public class Entity1_13Types { @AllArgsConstructor @Getter public enum ObjectTypes { - AREA_EFFECT_CLOUD(0, EntityType.AREA_EFFECT_CLOUD), - ARMOR_STAND(1, EntityType.ARMOR_STAND), - BOAT(5, EntityType.BOAT), - ITEM(30, EntityType.DROPPED_ITEM), - MINECART(37, EntityType.MINECART_ABSTRACT), - TNT_PRIMED(53, EntityType.PRIMED_TNT), - ENDER_CRYSTAL(14, EntityType.ENDER_CRYSTAL), - TIPPED_ARROW(2, EntityType.ARROW), - SNOWBALL(65, EntityType.SNOWBALL), - EGG(71, EntityType.EGG), - FIREBALL(32, EntityType.FIREBALL), - SMALL_FIREBALL(63, EntityType.SMALL_FIREBALL), - ENDER_PEARL(72, EntityType.ENDER_PEARL), - WITHER_SKULL(82, EntityType.WITHER_SKULL), - SHULKER_BULLET(58, EntityType.SHULKER_BULLET), - LIAMA_SPIT(35, EntityType.LIAMA_SPIT), - FALLING_BLOCK(22, EntityType.FALLING_BLOCK), - ITEM_FRAME(31, EntityType.ITEM_FRAME), - ENDER_SIGNAL(21, EntityType.ENDER_SIGNAL), - POTION(74, EntityType.SPLASH_POTION), - THROWN_EXP_BOTTLE(73, EntityType.THROWN_EXP_BOTTLE), - FIREWORK(23, EntityType.FIREWORK), - LEASH(33, EntityType.LEASH_HITCH), - EVOCATION_FANGS(18, EntityType.EVOCATION_FANGS), + BOAT(1, EntityType.BOAT), + ITEM(2, EntityType.DROPPED_ITEM), + AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD), + MINECART(10, EntityType.MINECART_ABSTRACT), + TNT_PRIMED(50, EntityType.PRIMED_TNT), + ENDER_CRYSTAL(51, EntityType.ENDER_CRYSTAL), + TIPPED_ARROW(60, EntityType.ARROW), + SNOWBALL(61, EntityType.SNOWBALL), + EGG(62, EntityType.EGG), + FIREBALL(63, EntityType.FIREBALL), + SMALL_FIREBALL(64, EntityType.SMALL_FIREBALL), + ENDER_PEARL(65, EntityType.ENDER_PEARL), + WITHER_SKULL(66, EntityType.WITHER_SKULL), + SHULKER_BULLET(67, EntityType.SHULKER_BULLET), + LIAMA_SPIT(68, EntityType.LIAMA_SPIT), + FALLING_BLOCK(70, EntityType.FALLING_BLOCK), + ITEM_FRAME(71, EntityType.ITEM_FRAME), + ENDER_SIGNAL(72, EntityType.ENDER_SIGNAL), + POTION(73, EntityType.SPLASH_POTION), + THROWN_EXP_BOTTLE(75, EntityType.THROWN_EXP_BOTTLE), + FIREWORK(76, EntityType.FIREWORK), + LEASH(77, EntityType.LEASH_HITCH), + ARMOR_STAND(78, EntityType.ARMOR_STAND), + EVOCATION_FANGS(79, EntityType.EVOCATION_FANGS), FISHIHNG_HOOK(90, EntityType.FISHING_HOOK), - SPECTRAL_ARROW(66, EntityType.SPECTRAL_ARROW), - DRAGON_FIREBALL(12, EntityType.DRAGON_FIREBALL); + SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), + DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL); private final int id; private final EntityType type; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/EntityTypeRewriter.java new file mode 100644 index 000000000..8437b93f2 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/data/EntityTypeRewriter.java @@ -0,0 +1,113 @@ +package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data; + + +import com.google.common.base.Optional; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +// Constant type changes to stop depending on names (the EntityTypes1_13 will be auto-generated so some fields can be obfuscated) +public class EntityTypeRewriter { + private static Map entityTypes = new ConcurrentHashMap<>(); + + static { + // Generated by Bevet + + // Entities 1.12 -> 18w11a + regEnt(1, 31); // item + regEnt(2, 21); // xp_orb + regEnt(3, 0); // area_effect_cloud + regEnt(4, 14); // elder_guardian + regEnt(5, 83); // wither_skeleton + regEnt(6, 70); // stray + regEnt(7, 73); // egg + regEnt(8, 34); // leash_knot + regEnt(9, 48); // painting + regEnt(10, 2); // arrow + regEnt(11, 66); // snowball + regEnt(12, 33); // fireball + regEnt(13, 64); // small_fireball + regEnt(14, 74); // ender_pearl + regEnt(15, 22); // eye_of_ender_signal + regEnt(16, 76); // potion + regEnt(17, 75); // xp_bottle + regEnt(18, 32); // item_frame + regEnt(19, 84); // wither_skull + regEnt(20, 54); // tnt + regEnt(21, 23); // falling_block + regEnt(22, 24); // fireworks_rocket + regEnt(23, 29); // husk + regEnt(24, 67); // spectral_arrow + regEnt(25, 59); // shulker_bullet + regEnt(26, 12); // dragon_fireball + regEnt(27, 88); // zombie_villager + regEnt(28, 62); // skeleton_horse + regEnt(29, 87); // zombie_horse + regEnt(30, 1); // armor_stand + regEnt(31, 11); // donkey + regEnt(32, 45); // mule + regEnt(33, 19); // evocation_fangs + regEnt(34, 20); // evocation_illager + regEnt(35, 77); // vex + regEnt(36, 80); // vindication_illager + regEnt(37, 30); // illusion_illager + regEnt(40, 40); // commandblock_minecart + regEnt(41, 5); // boat + regEnt(42, 38); // minecart + regEnt(43, 39); // chest_minecart + regEnt(44, 41); // furnace_minecart + regEnt(45, 44); // tnt_minecart + regEnt(46, 42); // hopper_minecart + regEnt(47, 43); // spawner_minecart + regEnt(50, 10); // creeper + regEnt(51, 61); // skeleton + regEnt(52, 68); // spider + regEnt(53, 26); // giant + regEnt(54, 86); // zombie + regEnt(55, 63); // slime + regEnt(56, 25); // ghast + regEnt(57, 52); // zombie_pigman + regEnt(58, 17); // enderman + regEnt(59, 6); // cave_spider + regEnt(60, 60); // silverfish + regEnt(61, 4); // blaze + regEnt(62, 37); // magma_cube + regEnt(63, 16); // ender_dragon + regEnt(64, 82); // wither + regEnt(65, 3); // bat + regEnt(66, 81); // witch + regEnt(67, 18); // endermite + regEnt(68, 27); // guardian + regEnt(69, 58); // shulker + regEnt(200, 15); // ender_crystal + regEnt(90, 50); // pig + regEnt(91, 57); // sheep + regEnt(92, 9); // cow + regEnt(93, 7); // chicken + regEnt(94, 69); // squid + regEnt(95, 85); // wolf + regEnt(96, 46); // mooshroom + regEnt(97, 65); // snowman + regEnt(98, 47); // ocelot + regEnt(99, 79); // villager_golem + regEnt(100, 28); // horse + regEnt(101, 55); // rabbit + regEnt(102, 53); // polar_bear + regEnt(103, 35); // llama + regEnt(104, 36); // llama_spit + regEnt(105, 49); // parrot + regEnt(120, 78); // villager + + + // OBJECTS + // Couldn't find any object id changes + } + + private static void regEnt(int type1_12, int type1_13) { + entityTypes.put(type1_12, type1_13); + } + + public static Optional getNewId(int type1_12) { + return Optional.fromNullable(entityTypes.get(type1_12)); + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java index 4a9ead852..c530691a1 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocolsnapshotto1_12_2/packets/EntityPackets.java @@ -2,7 +2,7 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets; import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.entities.Entity1_12Types; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; @@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.MetadataRewriter; +import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.EntityTypeRewriter; import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.storage.EntityTracker; public class EntityPackets { @@ -25,22 +26,24 @@ public class EntityPackets { map(Type.VAR_INT); // 0 - Entity id map(Type.UUID); // 1 - UUID map(Type.BYTE); // 2 - Type - // TODO handle new 1.13 entities + // Track Entity handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); byte type = wrapper.get(Type.BYTE, 0); + Optional entType = Entity1_13Types.ObjectTypes.findById(type); - Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.valueOf( - Entity1_12Types.getTypeFromId(type, true).name() - ); + if (!entType.isPresent()) { + Via.getPlatform().getLogger().severe("No object type id registered! " + type); + return; + } - wrapper.set(Type.BYTE, 0, (byte) entType.getId()); + // TODO no object type changes so far // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + wrapper.user().get(EntityTracker.class).addEntity(entityId, entType.get().getType()); } }); } @@ -70,11 +73,13 @@ public class EntityPackets { int entityId = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 1); - Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.valueOf( - Entity1_12Types.getTypeFromId(type, false).name() - ); + Optional optNewType = EntityTypeRewriter.getNewId(type); + type = optNewType.or(type); + Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false); + + + wrapper.set(Type.VAR_INT, 1, type); - wrapper.set(Type.VAR_INT, 1, type = entType.getId()); // Register Type ID wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);