From 8f92d55747adaf1db237b4d5e3cbbeb70e23fa6c Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Tue, 14 May 2024 15:31:40 +0200 Subject: [PATCH] Update Via API usage (#747) --- .../api/rewriters/LegacyBlockItemRewriter.java | 4 ++-- .../rewriter/EntityPacketRewriter1_10.java | 4 ++-- .../rewriter/EntityPacketRewriter1_11_1.java | 6 +++--- .../rewriter/BlockItemPacketRewriter1_11.java | 2 +- .../rewriter/EntityPacketRewriter1_11.java | 18 +++++++++--------- .../rewriter/EntityPacketRewriter1_12.java | 9 ++++----- .../rewriter/EntityPacketRewriter1_13_1.java | 2 +- .../rewriter/EntityPacketRewriter1_13.java | 9 +++------ .../rewriter/EntityPacketRewriter1_14.java | 13 ++++++++----- 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index 41921b85..49dc5d20 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -227,8 +227,8 @@ public abstract class LegacyBlockItemRewriter { - final Optional type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0)); - if (type.isPresent() && type.get() == EntityTypes1_12.ObjectType.FALLING_BLOCK) { + final EntityTypes1_12.ObjectType type = EntityTypes1_12.ObjectType.findById(wrapper.get(Types.BYTE, 0)); + if (type == EntityTypes1_12.ObjectType.FALLING_BLOCK) { final int objectData = wrapper.get(Types.INT, 0); final IdAndData block = handleBlock(objectData & 4095, objectData >> 12 & 15); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/EntityPacketRewriter1_10.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/EntityPacketRewriter1_10.java index 4055b690..161a735f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/EntityPacketRewriter1_10.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/EntityPacketRewriter1_10.java @@ -56,14 +56,14 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter EntityTypes1_11.ObjectType.findById(id).orElse(null))); + handler(getObjectRewriter(EntityTypes1_11.ObjectType::findById)); handler(protocol.getItemRewriter().getFallingBlockHandler()); } }); registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_10.EntityType.EXPERIENCE_ORB); - registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_10.EntityType.WEATHER); + registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_10.EntityType.LIGHTNING_BOLT); protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() { @Override diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/rewriter/EntityPacketRewriter1_11_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/rewriter/EntityPacketRewriter1_11_1.java index 30889742..0428933f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/rewriter/EntityPacketRewriter1_11_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11_1to1_11/rewriter/EntityPacketRewriter1_11_1.java @@ -51,12 +51,12 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter EntityTypes1_11.ObjectType.findById(id).orElse(null))); + handler(getObjectRewriter(EntityTypes1_11.ObjectType::findById)); } }); registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB); - registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER); + registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.LIGHTNING_BOLT); protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() { @Override @@ -110,7 +110,7 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter EntityTypes1_11.ObjectType.findById(id).orElse(null))); + handler(getObjectRewriter(EntityTypes1_11.ObjectType::findById)); handler(protocol.getItemRewriter().getFallingBlockHandler()); } }); registerTracker(ClientboundPackets1_9_3.ADD_EXPERIENCE_ORB, EntityTypes1_11.EntityType.EXPERIENCE_ORB); - registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.WEATHER); + registerTracker(ClientboundPackets1_9_3.ADD_GLOBAL_ENTITY, EntityTypes1_11.EntityType.LIGHTNING_BOLT); protocol.registerClientbound(ClientboundPackets1_9_3.ADD_MOB, new PacketHandlers() { @Override @@ -189,16 +189,16 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter storage.add(getHorseMetaType(4))); mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3))); // New mobs - mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_FANGS, EntityTypes1_11.EntityType.SHULKER); - mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOCATION_ILLAGER, EntityTypes1_11.EntityType.VILLAGER).plainName(); + mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER_FANGS, EntityTypes1_11.EntityType.SHULKER); + mapEntityTypeWithData(EntityTypes1_11.EntityType.EVOKER, EntityTypes1_11.EntityType.VILLAGER).plainName(); mapEntityTypeWithData(EntityTypes1_11.EntityType.VEX, EntityTypes1_11.EntityType.BAT).plainName(); mapEntityTypeWithData(EntityTypes1_11.EntityType.VINDICATOR, EntityTypes1_11.EntityType.VILLAGER).plainName().spawnMetadata(storage -> storage.add(new EntityData(13, EntityDataTypes1_9.VAR_INT, 4))); // Base Profession mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA, EntityTypes1_11.EntityType.HORSE).plainName().spawnMetadata(storage -> storage.add(getHorseMetaType(1))); mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA_SPIT, EntityTypes1_11.EntityType.SNOWBALL); - mapObjectType(EntityTypes1_11.ObjectType.LIAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1); + mapObjectType(EntityTypes1_11.ObjectType.LLAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1); // Replace with endertorchthingies - mapObjectType(EntityTypes1_11.ObjectType.EVOCATION_FANGS, EntityTypes1_11.ObjectType.FALLING_BLOCK, 198 | 1 << 12); + mapObjectType(EntityTypes1_11.ObjectType.EVOKER_FANGS, EntityTypes1_11.ObjectType.FALLING_BLOCK, 198 | 1 << 12); // Handle ElderGuardian & target metadata filter().type(EntityTypes1_11.EntityType.GUARDIAN).index(12).handler((event, meta) -> { @@ -232,7 +232,7 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { + filter().type(EntityTypes1_11.EntityType.EVOKER).index(12).handler((event, meta) -> { event.setIndex(13); meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Byte) meta.getValue()).intValue()); // Change the profession for the states }); @@ -243,7 +243,7 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { + filter().type(EntityTypes1_11.EntityType.VINDICATOR).index(12).handler((event, meta) -> { event.setIndex(13); meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Number) meta.getValue()).intValue() == 1 ? 2 : 4); }); @@ -283,7 +283,7 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { + filter().type(EntityTypes1_11.EntityType.LLAMA).handler((event, meta) -> { StoredEntityData data = storedEntityData(event); ChestedHorseStorage storage = data.get(ChestedHorseStorage.class); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java index 409330cf..493b5e46 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_12to1_11_1/rewriter/EntityPacketRewriter1_12.java @@ -59,14 +59,14 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter EntityTypes1_12.ObjectType.findById(id).orElse(null))); + handler(getObjectRewriter(EntityTypes1_12.ObjectType::findById)); handler(protocol.getItemRewriter().getFallingBlockHandler()); } }); registerTracker(ClientboundPackets1_12.ADD_EXPERIENCE_ORB, EntityTypes1_12.EntityType.EXPERIENCE_ORB); - registerTracker(ClientboundPackets1_12.ADD_GLOBAL_ENTITY, EntityTypes1_12.EntityType.WEATHER); + registerTracker(ClientboundPackets1_12.ADD_GLOBAL_ENTITY, EntityTypes1_12.EntityType.LIGHTNING_BOLT); protocol.registerClientbound(ClientboundPackets1_12.ADD_MOB, new PacketHandlers() { @Override @@ -196,10 +196,9 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter { + filter().type(EntityTypes1_12.EntityType.ILLUSIONER).index(0).handler((event, meta) -> { byte mask = (byte) meta.getValue(); if ((mask & 0x20) == 0x20) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java index 76a92a16..687c9ec7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_1to1_13/rewriter/EntityPacketRewriter1_13_1.java @@ -155,7 +155,7 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter { + filter().type(EntityTypes1_13.EntityType.ABSTRACT_MINECART).index(9).handler((event, meta) -> { int data = (int) meta.getValue(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java index b9c92d10..2ac656d0 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13to1_12_2/rewriter/EntityPacketRewriter1_13.java @@ -90,10 +90,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter { - Optional optionalType = EntityTypes1_13.ObjectType.findById(wrapper.get(Types.BYTE, 0)); - if (optionalType.isEmpty()) return; - - EntityTypes1_13.ObjectType type = optionalType.get(); + EntityTypes1_13.ObjectType type = EntityTypes1_13.ObjectType.findById(wrapper.get(Types.BYTE, 0)); if (type == EntityTypes1_13.ObjectType.FALLING_BLOCK) { int blockState = wrapper.get(Types.INT, 0); int combined = Protocol1_13To1_12_2.MAPPINGS.getNewBlockStateId(blockState); @@ -308,8 +305,8 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter 1; @@ -156,7 +154,12 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter