From bb48dc90f99afec6a82c9373d601684d16b5c4f5 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Thu, 6 Jun 2024 11:00:18 +0200 Subject: [PATCH] Add EntityRewriter#registerBlockStateHandler (#3912) --- .../v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java | 8 +++----- .../rewriter/EntityPacketRewriter1_13_1.java | 6 ++---- .../v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java | 5 +---- .../v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java | 6 ++---- .../rewriter/EntityPacketRewriter1_16_2.java | 6 ++---- .../v1_16_4to1_17/rewriter/EntityPacketRewriter1_17.java | 6 +----- .../v1_18_2to1_19/rewriter/EntityPacketRewriter1_19.java | 7 +------ .../rewriter/EntityPacketRewriter1_19_3.java | 6 +----- .../rewriter/EntityPacketRewriter1_19_4.java | 6 +----- .../v1_19_4to1_20/rewriter/EntityPacketRewriter1_20.java | 6 +----- .../rewriter/EntityPacketRewriter1_20_3.java | 6 +----- .../rewriter/EntityPacketRewriter1_20_5.java | 7 ++----- .../rewriter/EntityPacketRewriter1_20_2.java | 6 +----- .../viaversion/viaversion/rewriter/EntityRewriter.java | 7 +++++++ .../protocols/rewriter/EntityPacketRewriter1_99.java | 6 +----- 15 files changed, 27 insertions(+), 67 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java index 7ef415ee1..92b59caaa 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java @@ -262,6 +262,9 @@ public class EntityPacketRewriter1_14 extends EntityRewriter { @@ -309,11 +312,6 @@ public class EntityPacketRewriter1_14 extends EntityRewriter { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); - filter().type(EntityTypes1_14.HORSE).index(18).handler((event, meta) -> { event.cancel(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java index e5410847e..5423d813f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13to1_13_1/rewriter/EntityPacketRewriter1_13_1.java @@ -109,10 +109,8 @@ public class EntityPacketRewriter1_13_1 extends EntityRewriter { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); + registerBlockStateHandler(EntityTypes1_13.EntityType.ABSTRACT_MINECART, 9); + filter().type(EntityTypes1_13.EntityType.ABSTRACT_ARROW).addIndex(7); // Shooter UUID } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java index 9e3480d57..e8d1690f3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_14_4to1_15/rewriter/EntityPacketRewriter1_15.java @@ -115,10 +115,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); + registerBlockStateHandler(EntityTypes1_15.ABSTRACT_MINECART, 10); filter().type(EntityTypes1_15.LIVING_ENTITY).addIndex(12); filter().type(EntityTypes1_15.WOLF).removeIndex(18); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java index c8dc0d0e8..4da5682ec 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_15_2to1_16/rewriter/EntityPacketRewriter1_16.java @@ -208,10 +208,8 @@ public class EntityPacketRewriter1_16 extends EntityRewriter { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); + registerBlockStateHandler(EntityTypes1_16.ABSTRACT_MINECART, 10); + filter().type(EntityTypes1_16.ABSTRACT_ARROW).removeIndex(8); filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> { byte mask = meta.value(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java index 2b47d8aec..5b69e75db 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_1to1_16_2/rewriter/EntityPacketRewriter1_16_2.java @@ -78,10 +78,8 @@ public class EntityPacketRewriter1_16_2 extends EntityRewriter { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); + registerBlockStateHandler(EntityTypes1_16_2.ABSTRACT_MINECART, 10); + filter().type(EntityTypes1_16_2.ABSTRACT_PIGLIN).handler((metadatas, meta) -> { if (meta.id() == 15) { meta.setId(16); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_4to1_17/rewriter/EntityPacketRewriter1_17.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_4to1_17/rewriter/EntityPacketRewriter1_17.java index 3f5e718e7..faab5373a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_4to1_17/rewriter/EntityPacketRewriter1_17.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_16_4to1_17/rewriter/EntityPacketRewriter1_17.java @@ -148,11 +148,7 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter { - // Convert to new block id - int data = (int) meta.getValue(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); + registerBlockStateHandler(EntityTypes1_17.ABSTRACT_MINECART, 11); // Attachment position removed filter().type(EntityTypes1_17.SHULKER).removeIndex(17); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/rewriter/EntityPacketRewriter1_19.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/rewriter/EntityPacketRewriter1_19.java index 9151554d5..0a4676f75 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/rewriter/EntityPacketRewriter1_19.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_18_2to1_19/rewriter/EntityPacketRewriter1_19.java @@ -335,12 +335,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter { - // Convert to new block id - final int data = (int) meta.getValue(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); + registerBlockStateHandler(EntityTypes1_19.ABSTRACT_MINECART, 11); filter().type(EntityTypes1_19.CAT).index(19).mapDataType(typeId -> Types1_19.ENTITY_DATA_TYPES.catVariantType); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/rewriter/EntityPacketRewriter1_19_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/rewriter/EntityPacketRewriter1_19_3.java index 7ec124db8..613ac8cf7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/rewriter/EntityPacketRewriter1_19_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_1to1_19_3/rewriter/EntityPacketRewriter1_19_3.java @@ -153,6 +153,7 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter Types1_19_3.ENTITY_DATA_TYPES.byId(typeId >= 2 ? typeId + 1 : typeId)); // Long added registerEntityDataTypeHandler(Types1_19_3.ENTITY_DATA_TYPES.itemType, Types1_19_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_3.ENTITY_DATA_TYPES.particleType); + registerBlockStateHandler(EntityTypes1_19_3.ABSTRACT_MINECART, 11); filter().type(EntityTypes1_19_3.ENTITY).index(6).handler((event, meta) -> { // Sitting pose added @@ -161,11 +162,6 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter { - // Convert to new block id - final int data = (int) meta.getValue(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - }); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_3to1_19_4/rewriter/EntityPacketRewriter1_19_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_3to1_19_4/rewriter/EntityPacketRewriter1_19_4.java index 5865bb42b..802a987e4 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_3to1_19_4/rewriter/EntityPacketRewriter1_19_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_3to1_19_4/rewriter/EntityPacketRewriter1_19_4.java @@ -221,11 +221,7 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter Types1_19_4.ENTITY_DATA_TYPES.byId(typeId >= 14 ? typeId + 1 : typeId)); // Optional block state (and map block state=14 to optional block state) registerEntityDataTypeHandler(Types1_19_4.ENTITY_DATA_TYPES.itemType, Types1_19_4.ENTITY_DATA_TYPES.blockStateType, Types1_19_4.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_4.ENTITY_DATA_TYPES.particleType, null); - - filter().type(EntityTypes1_19_4.ABSTRACT_MINECART).index(11).handler((event, meta) -> { - final int blockState = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); - }); + registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11); filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> { final int boatType = meta.value(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_4to1_20/rewriter/EntityPacketRewriter1_20.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_4to1_20/rewriter/EntityPacketRewriter1_20.java index b337222ac..ad388e485 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_4to1_20/rewriter/EntityPacketRewriter1_20.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_19_4to1_20/rewriter/EntityPacketRewriter1_20.java @@ -129,6 +129,7 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter { @@ -144,11 +145,6 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter { - final int blockState = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); - }); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java index 2eafb1bf5..bd7c75e2f 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_2to1_20_3/rewriter/EntityPacketRewriter1_20_3.java @@ -135,11 +135,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter { - final int blockState = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); - }); + registerBlockStateHandler(EntityTypes1_20_3.ABSTRACT_MINECART, 11); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java index b1a24a4bd..6e716e5cc 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java @@ -413,6 +413,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter protocol.getComponentRewriter().processTag(event.user(), meta.value())); filter().dataType(Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType).handler((event, meta) -> protocol.getComponentRewriter().processTag(event.user(), meta.value())); @@ -479,11 +481,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { - final int blockState = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); - }); } private void addColor(@Nullable final EntityData particleMeta, final int color) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java index e4587c7ee..7fb55a257 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20to1_20_2/rewriter/EntityPacketRewriter1_20_2.java @@ -174,13 +174,9 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter { - final int blockState = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); - }); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index 1b7fab115..075be1f74 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -223,6 +223,13 @@ public abstract class EntityRewriter { + final int data = (int) meta.getValue(); + meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + }); + } + public void registerTracker(C packetType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java b/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java index c9a2e27ec..0b424f50e 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java +++ b/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java @@ -101,12 +101,8 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter { - final int blockState = data.value(); - data.setValue(protocol.getMappingData().getNewBlockStateId(blockState)); - }); + registerBlockStateHandler(EntityTypes1_20_5.ABSTRACT_MINECART, 11); } @Override