From a27e439c99e8de159835a085453e10def739426e Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Wed, 30 Jan 2019 17:48:11 +0100 Subject: [PATCH] remove 1.14 object type (Mojang removed objcet trype in 19w05a) fix entity type remaps --- .../api/entities/Entity1_14Types.java | 61 +------------------ .../data/EntityTypeRewriter.java | 46 +++++++------- .../packets/EntityPackets.java | 20 +++--- 3 files changed, 37 insertions(+), 90 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java index 103c7f57d..5b6ac5409 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java +++ b/common/src/main/java/us/myles/ViaVersion/api/entities/Entity1_14Types.java @@ -7,11 +7,11 @@ import us.myles.ViaVersion.api.Via; public class Entity1_14Types { - public static EntityType getTypeFromId(int typeID, boolean isObject) { - Optional type = isObject ? ObjectTypes.getPCEntity(typeID) : EntityType.findById(typeID); + public static EntityType getTypeFromId(int typeID) { + Optional type = EntityType.findById(typeID); if (!type.isPresent()) { - Via.getPlatform().getLogger().severe("Could not find type id " + typeID + " isObject=" + isObject); + Via.getPlatform().getLogger().severe("Could not find type id " + typeID); return EntityType.ENTITY; // Fall back to the basic ENTITY } @@ -238,59 +238,4 @@ public class Entity1_14Types { return false; } } - - @AllArgsConstructor - @Getter - public enum ObjectTypes { - BOAT(1, EntityType.BOAT), - ITEM(2, EntityType.ITEM), - AREA_EFFECT_CLOUD(3, EntityType.AREA_EFFECT_CLOUD), - MINECART(10, EntityType.MINECART_ABSTRACT), - TNT_PRIMED(50, EntityType.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.LLAMA_SPIT), - FALLING_BLOCK(70, EntityType.FALLING_BLOCK), - ITEM_FRAME(71, EntityType.ITEM_FRAME), - ENDER_SIGNAL(72, EntityType.EYE_OF_ENDER_SIGNAL), - POTION(73, EntityType.POTION), - THROWN_EXP_BOTTLE(75, EntityType.XP_BOTTLE), - FIREWORK(76, EntityType.FIREWORKS_ROCKET), - LEASH(77, EntityType.LEASH_KNOT), - ARMOR_STAND(78, EntityType.ARMOR_STAND), - EVOCATION_FANGS(79, EntityType.EVOCATION_FANGS), - FISHIHNG_HOOK(90, EntityType.FISHING_BOBBER), - SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), - DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL), - ; - - private final int id; - private final EntityType type; - - public static Optional findById(int id) { - if (id == -1) - return Optional.absent(); - - for (ObjectTypes ent : ObjectTypes.values()) - if (ent.getId() == id) - return Optional.of(ent); - - return Optional.absent(); - } - - public static Optional getPCEntity(int id) { - Optional output = findById(id); - - if (!output.isPresent()) - return Optional.absent(); - return Optional.of(output.get().getType()); - } - } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java index 1f68cb84e..57eb88bd3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/data/EntityTypeRewriter.java @@ -74,29 +74,29 @@ public class EntityTypeRewriter { regEnt(69, 71); // spider regEnt(70, 72); // squid regEnt(71, 73); // stray - regEnt(72, 74); // tropical_fish - regEnt(73, 75); // turtle - regEnt(74, 76); // egg - regEnt(75, 77); // ender_pearl - regEnt(76, 78); // experience_bottle - regEnt(77, 79); // potion - regEnt(78, 80); // vex - regEnt(79, 81); // villager - regEnt(80, 82); // iron_golem - regEnt(81, 83); // vindicator - regEnt(82, 85); // witch - regEnt(83, 86); // wither - regEnt(84, 87); // wither_skeleton - regEnt(85, 88); // wither_skull - regEnt(86, 89); // wolf - regEnt(87, 90); // zombie - regEnt(88, 91); // zombie_horse - regEnt(89, 92); // zombie_villager - regEnt(90, 93); // phantom - regEnt(91, 95); // lightning_bolt - regEnt(92, 96); // player - regEnt(93, 97); // fishing_bobber - regEnt(94, 98); // trident + regEnt(72, 75); // tropical_fish + regEnt(73, 76); // turtle + regEnt(74, 77); // egg + regEnt(75, 78); // ender_pearl + regEnt(76, 79); // experience_bottle + regEnt(77, 80); // potion + regEnt(78, 82); // vex + regEnt(79, 83); // villager + regEnt(80, 84); // iron_golem + regEnt(81, 85); // vindicator + regEnt(82, 88); // witch + regEnt(83, 89); // wither + regEnt(84, 90); // wither_skeleton + regEnt(85, 91); // wither_skull + regEnt(86, 92); // wolf + regEnt(87, 93); // zombie + regEnt(88, 94); // zombie_horse + regEnt(89, 95); // zombie_villager + regEnt(90, 96); // phantom + regEnt(91, 98); // lightning_bolt + regEnt(92, 99); // player + regEnt(93, 100); // fishing_bobber + regEnt(94, 81); // trident } private static void regEnt(int type1_13, int type1_14) { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java index e57212213..0996fbbd6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/packets/EntityPackets.java @@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets; import com.google.common.base.Optional; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketHandler; @@ -41,21 +42,22 @@ public class EntityPackets { public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); UUID uuid = wrapper.get(Type.UUID, 0); - int type = wrapper.get(Type.VAR_INT, 1); - Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type, true); + int typeId = wrapper.get(Type.VAR_INT, 1); - if (entType != null) { - if (entType.is(Entity1_14Types.EntityType.FALLING_BLOCK)) { + Entity1_13Types.EntityType type1_13 = Entity1_13Types.getTypeFromId(typeId, true); + typeId = EntityTypeRewriter.getNewId(type1_13.getId()).or(type1_13.getId()); + Entity1_14Types.EntityType type1_14 = Entity1_14Types.getTypeFromId(typeId); + + if (type1_14 != null) { + if (type1_14.is(Entity1_14Types.EntityType.FALLING_BLOCK)) { int data = wrapper.get(Type.INT, 0); wrapper.set(Type.INT, 0, Protocol1_14To1_13_2.getNewBlockStateId(data)); } - - type = entType.getId(); } - wrapper.set(Type.VAR_INT, 1, type); + wrapper.set(Type.VAR_INT, 1, typeId); // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, uuid, entType); + wrapper.user().get(EntityTracker.class).addEntity(entityId, uuid, type1_14); } }); } @@ -88,7 +90,7 @@ public class EntityPackets { type = EntityTypeRewriter.getNewId(type).or(type); - Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type, false); + Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); wrapper.set(Type.VAR_INT, 1, type);