diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityReplacement.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityReplacement.java index e38b53d5..25b89e8b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityReplacement.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityReplacement.java @@ -31,7 +31,7 @@ public class EntityReplacement { private final int replacementId; private final String key; private ComponentType componentType = ComponentType.NONE; - private MetaCreator defaultMeta; + private EntityDataCreator defaultData; public EntityReplacement(BackwardsProtocol protocol, EntityType type, int replacementId) { this(protocol, type.name(), type.getId(), replacementId); @@ -59,13 +59,13 @@ public class EntityReplacement { return this; } - public EntityReplacement spawnMetadata(MetaCreator handler) { - this.defaultMeta = handler; + public EntityReplacement spawnEntityData(EntityDataCreator handler) { + this.defaultData = handler; return this; } - public boolean hasBaseMeta() { - return this.defaultMeta != null; + public boolean hasBaseData() { + return this.defaultData != null; } public int typeId() { @@ -97,8 +97,8 @@ public class EntityReplacement { return replacementId; } - public @Nullable MetaCreator defaultMeta() { - return defaultMeta; + public @Nullable EntityDataCreator defaultData() { + return defaultData; } public boolean isObjectType() { @@ -111,18 +111,20 @@ public class EntityReplacement { @Override public String toString() { - return "EntityData{" + - "id=" + id + - ", mobName='" + key + '\'' + + return "EntityReplacement{" + + "protocol=" + protocol + + ", id=" + id + ", replacementId=" + replacementId + - ", defaultMeta=" + defaultMeta + + ", key='" + key + '\'' + + ", componentType=" + componentType + + ", defaultData=" + defaultData + '}'; } @FunctionalInterface - public interface MetaCreator { + public interface EntityDataCreator { - void createMeta(WrappedMetadata storage); + void createData(WrappedEntityData storage); } private enum ComponentType { diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/WrappedMetadata.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/WrappedEntityData.java similarity index 77% rename from common/src/main/java/com/viaversion/viabackwards/api/entities/storage/WrappedMetadata.java rename to common/src/main/java/com/viaversion/viabackwards/api/entities/storage/WrappedEntityData.java index a3916fe5..034ede24 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/WrappedMetadata.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/WrappedEntityData.java @@ -22,28 +22,28 @@ import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import java.util.List; import org.checkerframework.checker.nullness.qual.Nullable; -public record WrappedMetadata(List metadataList) { +public record WrappedEntityData(List entityDataList) { public boolean has(EntityData data) { - return this.metadataList.contains(data); + return this.entityDataList.contains(data); } public void remove(EntityData data) { - this.metadataList.remove(data); + this.entityDataList.remove(data); } public void remove(int index) { - metadataList.removeIf(meta -> meta.id() == index); + entityDataList.removeIf(data -> data.id() == index); } public void add(EntityData data) { - this.metadataList.add(data); + this.entityDataList.add(data); } public @Nullable EntityData get(int index) { - for (EntityData meta : this.metadataList) { - if (index == meta.id()) { - return meta; + for (EntityData data : this.entityDataList) { + if (index == data.id()) { + return data; } } return null; diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java index be17ad74..8ff68763 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java @@ -21,7 +21,7 @@ import com.google.common.base.Preconditions; import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement; -import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; +import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.data.entity.TrackedEntity; @@ -50,24 +50,24 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ public abstract class EntityRewriterBase> extends EntityRewriter { private final Int2ObjectMap entityDataMappings = new Int2ObjectOpenHashMap<>(); - private final EntityDataType displayNameMetaType; - private final EntityDataType displayVisibilityMetaType; + private final EntityDataType displayNameDataType; + private final EntityDataType displayVisibilityDataType; private final int displayNameIndex; private final int displayVisibilityIndex; - EntityRewriterBase(T protocol, EntityDataType displayNameMetaType, int displayNameIndex, - EntityDataType displayVisibilityMetaType, int displayVisibilityIndex) { + EntityRewriterBase(T protocol, EntityDataType displayNameDataType, int displayNameIndex, + EntityDataType displayVisibilityDataType, int displayVisibilityIndex) { super(protocol, false); - this.displayNameMetaType = displayNameMetaType; + this.displayNameDataType = displayNameDataType; this.displayNameIndex = displayNameIndex; - this.displayVisibilityMetaType = displayVisibilityMetaType; + this.displayVisibilityDataType = displayVisibilityDataType; this.displayVisibilityIndex = displayVisibilityIndex; } @Override public void handleEntityData(int entityId, List entityDataList, UserConnection connection) { final TrackedEntity entity = tracker(connection).entity(entityId); - final boolean initialMetadata = !(entity != null && entity.hasSentEntityData()); + final boolean initialEntityData = !(entity != null && entity.hasSentEntityData()); super.handleEntityData(entityId, entityDataList, connection); @@ -80,37 +80,37 @@ public abstract class EntityRewriterBase metadataList) { + private void addDisplayVisibilityData(List entityDataList) { if (alwaysShowOriginalMobName()) { - removeMeta(displayVisibilityIndex, metadataList); - metadataList.add(new EntityData(displayVisibilityIndex, displayVisibilityMetaType, getDisplayVisibilityMetaValue())); + removeData(displayVisibilityIndex, entityDataList); + entityDataList.add(new EntityData(displayVisibilityIndex, displayVisibilityDataType, getDisplayVisibilityDataValue())); } } - protected Object getDisplayVisibilityMetaValue() { + protected Object getDisplayVisibilityDataValue() { return true; } @@ -118,17 +118,17 @@ public abstract class EntityRewriterBase metadataList) { - for (EntityData metadata : metadataList) { - if (metadata.id() == metaIndex) { - return metadata; + protected @Nullable EntityData getData(int dataIndex, List entityDataList) { + for (EntityData entityData : entityDataList) { + if (entityData.id() == dataIndex) { + return entityData; } } return null; } - protected void removeMeta(int metaIndex, List metadataList) { - metadataList.removeIf(meta -> meta.id() == metaIndex); + protected void removeData(int dataIndex, List entityDataList) { + entityDataList.removeIf(data -> data.id() == dataIndex); } protected boolean hasData(EntityType type) { @@ -163,7 +163,7 @@ public abstract class EntityRewriterBase { - EntityDataType type = meta.dataType(); + filter().handler((event, data) -> { + EntityDataType type = data.dataType(); if (type == itemType) { - protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()); + protocol.getItemRewriter().handleItemToClient(event.user(), data.value()); } else if (type == blockStateType) { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + int value = data.value(); + data.setValue(protocol.getMappingData().getNewBlockStateId(value)); } else if (type == optionalBlockStateType) { - int data = meta.value(); - if (data != 0) { - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + int value = data.value(); + if (value != 0) { + data.setValue(protocol.getMappingData().getNewBlockStateId(value)); } } else if (type == particleType) { - rewriteParticle(event.user(), meta.value()); + rewriteParticle(event.user(), data.value()); } else if (type == optionalComponentType || type == componentType) { - JsonElement text = meta.value(); + JsonElement text = data.value(); protocol.getComponentRewriter().processText(event.user(), text); } }); } - public void registerMetaTypeHandler1_20_3( + public void registerEntityDataTypeHandler1_20_3( @Nullable EntityDataType itemType, @Nullable EntityDataType blockStateType, @Nullable EntityDataType optionalBlockStateType, @@ -201,27 +201,27 @@ public abstract class EntityRewriterBase { - EntityDataType type = meta.dataType(); + filter().handler((event, data) -> { + EntityDataType type = data.dataType(); if (type == itemType) { - meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())); + data.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), data.value())); } else if (type == blockStateType) { - int data = meta.value(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + int value = data.value(); + data.setValue(protocol.getMappingData().getNewBlockStateId(value)); } else if (type == optionalBlockStateType) { - int data = meta.value(); - if (data != 0) { - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); + int value = data.value(); + if (value != 0) { + data.setValue(protocol.getMappingData().getNewBlockStateId(value)); } } else if (type == particleType) { - rewriteParticle(event.user(), meta.value()); + rewriteParticle(event.user(), data.value()); } else if (type == particlesType) { - Particle[] particles = meta.value(); + Particle[] particles = data.value(); for (final Particle particle : particles) { rewriteParticle(event.user(), particle); } } else if (type == optionalComponentType || type == componentType) { - protocol.getComponentRewriter().processTag(event.user(), meta.value()); + protocol.getComponentRewriter().processTag(event.user(), data.value()); } }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java index 9fe2e08d..61544ff5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java @@ -20,7 +20,7 @@ package com.viaversion.viabackwards.api.rewriters; import com.viaversion.viabackwards.api.BackwardsProtocol; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement; import com.viaversion.viabackwards.api.entities.storage.EntityObjectData; -import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; +import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData; import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.ObjectType; @@ -90,64 +90,64 @@ public abstract class LegacyEntityRewriter> oldMetaType, Type> newMetaType) { + public void registerSetEntityData(C packetType, Type> dataType, Type> mappedDataType) { protocol.registerClientbound(packetType, new PacketHandlers() { @Override public void register() { map(Types.VAR_INT); // 0 - Entity ID - if (oldMetaType != null) { - map(oldMetaType, newMetaType); + if (dataType != null) { + map(dataType, mappedDataType); } else { - map(newMetaType); + map(mappedDataType); } handler(wrapper -> { - List metadata = wrapper.get(newMetaType, 0); - handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); + List entityDataList = wrapper.get(mappedDataType, 0); + handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user()); }); } }); } @Override - public void registerSetEntityData(C packetType, Type> metaType) { - registerSetEntityData(packetType, null, metaType); + public void registerSetEntityData(C packetType, Type> dataType) { + registerSetEntityData(packetType, null, dataType); } - protected PacketHandler getMobSpawnRewriter(Type> metaType, IdSetter idSetter) { + protected PacketHandler getMobSpawnRewriter(Type> dataType, IdSetter idSetter) { return wrapper -> { int entityId = wrapper.get(Types.VAR_INT, 0); EntityType type = tracker(wrapper.user()).entityType(entityId); - List metadata = wrapper.get(metaType, 0); - handleEntityData(entityId, metadata, wrapper.user()); + List entityDataList = wrapper.get(dataType, 0); + handleEntityData(entityId, entityDataList, wrapper.user()); EntityReplacement entityReplacement = entityDataForType(type); if (entityReplacement != null) { idSetter.setId(wrapper, entityReplacement.replacementId()); - if (entityReplacement.hasBaseMeta()) { - entityReplacement.defaultMeta().createMeta(new WrappedMetadata(metadata)); + if (entityReplacement.hasBaseData()) { + entityReplacement.defaultData().createData(new WrappedEntityData(entityDataList)); } } }; } - public PacketHandler getMobSpawnRewriter(Type> metaType) { - return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Types.UNSIGNED_BYTE, 0, (short) id)); + public PacketHandler getMobSpawnRewriter(Type> dataType) { + return getMobSpawnRewriter(dataType, (wrapper, id) -> wrapper.set(Types.UNSIGNED_BYTE, 0, (short) id)); } - public PacketHandler getMobSpawnRewriter1_11(Type> metaType) { - return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Types.VAR_INT, 1, id)); + public PacketHandler getMobSpawnRewriter1_11(Type> dataType) { + return getMobSpawnRewriter(dataType, (wrapper, id) -> wrapper.set(Types.VAR_INT, 1, id)); } protected PacketHandler getObjectTrackerHandler() { return wrapper -> addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), objectTypeFromId(wrapper.get(Types.BYTE, 0))); } - protected PacketHandler getTrackerAndMetaHandler(Type> metaType, EntityType entityType) { + protected PacketHandler getTrackerAndDataHandler(Type> dataType, EntityType entityType) { return wrapper -> { addTrackedEntity(wrapper, wrapper.get(Types.VAR_INT, 0), entityType); - List metadata = wrapper.get(metaType, 0); - handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); + List entityDataList = wrapper.get(dataType, 0); + handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user()); }; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/BlockItemPacketRewriter1_10.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/BlockItemPacketRewriter1_10.java index 2acb10d3..9e76254c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/BlockItemPacketRewriter1_10.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_10to1_9_3/rewriter/BlockItemPacketRewriter1_10.java @@ -58,10 +58,10 @@ public class BlockItemPacketRewriter1_10 extends LegacyBlockItemRewriter { - if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item - meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); + // Rewrite entity data items + protocol.getEntityRewriter().filter().handler((event, data) -> { + if (data.dataType().type().equals(Types.ITEM1_8)) // Is Item + data.setValue(handleItemToClient(event.user(), (Item) data.getValue())); }); // Particle 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 161a735f..ba013d40 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 @@ -19,7 +19,7 @@ package com.viaversion.viabackwards.protocol.v1_10to1_9_3.rewriter; import com.viaversion.viabackwards.api.entities.storage.EntityReplacement; -import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; +import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3; import com.viaversion.viaversion.api.minecraft.entities.EntityType; @@ -80,25 +80,25 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter { int entityId = wrapper.get(Types.VAR_INT, 0); EntityType type = tracker(wrapper.user()).entityType(entityId); - List metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); - handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); + List entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); + handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user()); EntityReplacement entityReplacement = entityDataForType(type); if (entityReplacement != null) { - WrappedMetadata storage = new WrappedMetadata(metadata); + WrappedEntityData storage = new WrappedEntityData(entityDataList); wrapper.set(Types.UNSIGNED_BYTE, 0, (short) entityReplacement.replacementId()); - if (entityReplacement.hasBaseMeta()) - entityReplacement.defaultMeta().createMeta(storage); + if (entityReplacement.hasBaseData()) + entityReplacement.defaultData().createData(storage); } }); @@ -119,9 +119,9 @@ public class EntityPacketRewriter1_10 extends LegacyEntityRewriter Standing up) - filter().type(EntityTypes1_10.EntityType.POLAR_BEAR).index(13).handler((event, meta) -> { - boolean b = (boolean) meta.getValue(); + filter().type(EntityTypes1_10.EntityType.POLAR_BEAR).index(13).handler((event, data) -> { + boolean b = (boolean) data.getValue(); - meta.setTypeAndValue(EntityDataTypes1_9.BYTE, b ? (byte) (14 & 0x0F) : (byte) (0)); + data.setTypeAndValue(EntityDataTypes1_9.BYTE, b ? (byte) (14 & 0x0F) : (byte) (0)); }); // Handle husk (index 13 -> Zombie Type) - filter().type(EntityTypes1_10.EntityType.ZOMBIE).index(13).handler((event, meta) -> { - if ((int) meta.getValue() == 6) { // Is type Husk - meta.setValue(0); + filter().type(EntityTypes1_10.EntityType.ZOMBIE).index(13).handler((event, data) -> { + if ((int) data.getValue() == 6) { // Is type Husk + data.setValue(0); } }); // Handle Stray (index 12 -> Skeleton Type) - filter().type(EntityTypes1_10.EntityType.SKELETON).index(12).handler((event, meta) -> { - if ((int) meta.getValue() == 2) { - meta.setValue(0); // Change to default skeleton + filter().type(EntityTypes1_10.EntityType.SKELETON).index(12).handler((event, data) -> { + if ((int) data.getValue() == 2) { + data.setValue(0); // Change to default skeleton } }); - // Handle the missing NoGravity tag for every metadata + // Handle the missing NoGravity tag for every entity data filter().removeIndex(5); } 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 0428933f..722f1e3a 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 @@ -23,7 +23,6 @@ import com.viaversion.viabackwards.protocol.v1_11_1to1_11.Protocol1_11_1To1_11; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_11; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_9; import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3; @@ -73,12 +72,12 @@ public class EntityPacketRewriter1_11_1 extends LegacyEntityRewriter { - if (meta.dataType().type().equals(Types.ITEM1_8)) { // Is Item - meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); + // Handle item entity data + protocol.getEntityRewriter().filter().handler((event, data) -> { + if (data.dataType().type().equals(Types.ITEM1_8)) { // Is Item + data.setValue(handleItemToClient(event.user(), (Item) data.getValue())); } }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/BlockItemPacketRewriter1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/BlockItemPacketRewriter1_11.java index 8e08f30e..ee029123 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/BlockItemPacketRewriter1_11.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/BlockItemPacketRewriter1_11.java @@ -243,9 +243,9 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter { - if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item - meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); + protocol.getEntityRewriter().filter().handler((event, data) -> { + if (data.dataType().type().equals(Types.ITEM1_8)) // Is Item + data.setValue(handleItemToClient(event.user(), (Item) data.getValue())); }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/EntityPacketRewriter1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/EntityPacketRewriter1_11.java index aa1d76f7..0a561756 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/EntityPacketRewriter1_11.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_11to1_10/rewriter/EntityPacketRewriter1_11.java @@ -18,7 +18,7 @@ package com.viaversion.viabackwards.protocol.v1_11to1_10.rewriter; -import com.viaversion.viabackwards.api.entities.storage.WrappedMetadata; +import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData; import com.viaversion.viabackwards.api.rewriters.LegacyEntityRewriter; import com.viaversion.viabackwards.protocol.v1_11to1_10.Protocol1_11To1_10; import com.viaversion.viabackwards.protocol.v1_11to1_10.data.SplashPotionMappings1_10; @@ -104,19 +104,19 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { - List metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); - if (metadata.isEmpty()) { - metadata.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0)); + List entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); + if (entityDataList.isEmpty()) { + entityDataList.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0)); } }); } @@ -136,14 +136,14 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { // Sub 1.11 clients will cry if the list is empty - List metadata = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); - if (metadata.isEmpty()) { - metadata.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0)); + List entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0); + if (entityDataList.isEmpty()) { + entityDataList.add(new EntityData(0, EntityDataTypes1_9.BYTE, (byte) 0)); } }); } @@ -177,39 +177,39 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter storage.add(getSkeletonTypeMeta(1))); - mapEntityTypeWithData(EntityTypes1_11.EntityType.STRAY, EntityTypes1_11.EntityType.SKELETON).plainName().spawnMetadata(storage -> storage.add(getSkeletonTypeMeta(2))); + mapEntityTypeWithData(EntityTypes1_11.EntityType.WITHER_SKELETON, EntityTypes1_11.EntityType.SKELETON).spawnEntityData(storage -> storage.add(getSkeletonTypeData(1))); + mapEntityTypeWithData(EntityTypes1_11.EntityType.STRAY, EntityTypes1_11.EntityType.SKELETON).plainName().spawnEntityData(storage -> storage.add(getSkeletonTypeData(2))); // Zombies - mapEntityTypeWithData(EntityTypes1_11.EntityType.HUSK, EntityTypes1_11.EntityType.ZOMBIE).plainName().spawnMetadata(storage -> handleZombieType(storage, 6)); - mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_VILLAGER, EntityTypes1_11.EntityType.ZOMBIE).spawnMetadata(storage -> handleZombieType(storage, 1)); + mapEntityTypeWithData(EntityTypes1_11.EntityType.HUSK, EntityTypes1_11.EntityType.ZOMBIE).plainName().spawnEntityData(storage -> handleZombieType(storage, 6)); + mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_VILLAGER, EntityTypes1_11.EntityType.ZOMBIE).spawnEntityData(storage -> handleZombieType(storage, 1)); // Horses - mapEntityTypeWithData(EntityTypes1_11.EntityType.HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(0))); // Nob able to ride the horse without having the MetaType sent. - mapEntityTypeWithData(EntityTypes1_11.EntityType.DONKEY, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(1))); - mapEntityTypeWithData(EntityTypes1_11.EntityType.MULE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(2))); - mapEntityTypeWithData(EntityTypes1_11.EntityType.SKELETON_HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(4))); - mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_HORSE, EntityTypes1_11.EntityType.HORSE).spawnMetadata(storage -> storage.add(getHorseMetaType(3))); + mapEntityTypeWithData(EntityTypes1_11.EntityType.HORSE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(0))); // Nob able to ride the horse without having the EntityDataType sent. + mapEntityTypeWithData(EntityTypes1_11.EntityType.DONKEY, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(1))); + mapEntityTypeWithData(EntityTypes1_11.EntityType.MULE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(2))); + mapEntityTypeWithData(EntityTypes1_11.EntityType.SKELETON_HORSE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(4))); + mapEntityTypeWithData(EntityTypes1_11.EntityType.ZOMBIE_HORSE, EntityTypes1_11.EntityType.HORSE).spawnEntityData(storage -> storage.add(getHorseDataType(3))); // New mobs 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.VINDICATOR, EntityTypes1_11.EntityType.VILLAGER).plainName().spawnEntityData(storage -> storage.add(new EntityData(13, EntityDataTypes1_9.VAR_INT, 4))); // Base Profession + mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA, EntityTypes1_11.EntityType.HORSE).plainName().spawnEntityData(storage -> storage.add(getHorseDataType(1))); mapEntityTypeWithData(EntityTypes1_11.EntityType.LLAMA_SPIT, EntityTypes1_11.EntityType.SNOWBALL); mapObjectType(EntityTypes1_11.ObjectType.LLAMA_SPIT, EntityTypes1_11.ObjectType.SNOWBALL, -1); // Replace with endertorchthingies 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) -> { - boolean b = (boolean) meta.getValue(); + // Handle ElderGuardian & target entity data + filter().type(EntityTypes1_11.EntityType.GUARDIAN).index(12).handler((event, data) -> { + boolean b = (boolean) data.getValue(); int bitmask = b ? 0x02 : 0; if (event.entityType() == EntityTypes1_11.EntityType.ELDER_GUARDIAN) { bitmask |= 0x04; } - meta.setTypeAndValue(EntityDataTypes1_9.BYTE, (byte) bitmask); + data.setTypeAndValue(EntityDataTypes1_9.BYTE, (byte) bitmask); }); // Handle skeleton swing @@ -218,34 +218,34 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { - switch (meta.id()) { + filter().type(EntityTypes1_11.EntityType.ZOMBIE).handler((event, data) -> { + switch (data.id()) { case 13 -> event.cancel(); case 14 -> event.setIndex(15); case 15 -> event.setIndex(14); case 16 -> { // Profession event.setIndex(13); - meta.setValue(1 + (int) meta.getValue()); + data.setValue(1 + (int) data.getValue()); } } }); // Handle Evocation Illager - filter().type(EntityTypes1_11.EntityType.EVOKER).index(12).handler((event, meta) -> { + filter().type(EntityTypes1_11.EntityType.EVOKER).index(12).handler((event, data) -> { event.setIndex(13); - meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Byte) meta.getValue()).intValue()); // Change the profession for the states + data.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Byte) data.getValue()).intValue()); // Change the profession for the states }); // Handle Vex (Remove this field completely since the position is not updated correctly when idling for bats. Sad ): - filter().type(EntityTypes1_11.EntityType.VEX).index(12).handler((event, meta) -> { - meta.setValue((byte) 0x00); + filter().type(EntityTypes1_11.EntityType.VEX).index(12).handler((event, data) -> { + data.setValue((byte) 0x00); }); // Handle VindicationIllager - filter().type(EntityTypes1_11.EntityType.VINDICATOR).index(12).handler((event, meta) -> { + filter().type(EntityTypes1_11.EntityType.VINDICATOR).index(12).handler((event, data) -> { event.setIndex(13); - meta.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Number) meta.getValue()).intValue() == 1 ? 2 : 4); + data.setTypeAndValue(EntityDataTypes1_9.VAR_INT, ((Number) data.getValue()).intValue() == 1 ? 2 : 4); }); /* @@ -253,20 +253,20 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { - StoredEntityData data = storedEntityData(event); - byte b = (byte) meta.getValue(); - if (data.has(ChestedHorseStorage.class) && data.get(ChestedHorseStorage.class).isChested()) { + filter().type(EntityTypes1_11.EntityType.ABSTRACT_HORSE).index(13).handler((event, data) -> { + StoredEntityData entityData = storedEntityData(event); + byte b = (byte) data.getValue(); + if (entityData.has(ChestedHorseStorage.class) && entityData.get(ChestedHorseStorage.class).isChested()) { b |= 0x08; // Chested - meta.setValue(b); + data.setValue(b); } }); // Create chested horse storage - filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).handler((event, meta) -> { - StoredEntityData data = storedEntityData(event); - if (!data.has(ChestedHorseStorage.class)) { - data.put(new ChestedHorseStorage()); + filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).handler((event, data) -> { + StoredEntityData entityData = storedEntityData(event); + if (!entityData.has(ChestedHorseStorage.class)) { + entityData.put(new ChestedHorseStorage()); } }); @@ -274,32 +274,32 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { - StoredEntityData data = storedEntityData(event); - ChestedHorseStorage storage = data.get(ChestedHorseStorage.class); - boolean b = (boolean) meta.getValue(); + filter().type(EntityTypes1_11.EntityType.CHESTED_HORSE).index(15).handler((event, data) -> { + StoredEntityData entityData = storedEntityData(event); + ChestedHorseStorage storage = entityData.get(ChestedHorseStorage.class); + boolean b = (boolean) data.getValue(); storage.setChested(b); event.cancel(); }); - // Get rid of Liama metadata - filter().type(EntityTypes1_11.EntityType.LLAMA).handler((event, meta) -> { - StoredEntityData data = storedEntityData(event); - ChestedHorseStorage storage = data.get(ChestedHorseStorage.class); + // Get rid of Liama entity data + filter().type(EntityTypes1_11.EntityType.LLAMA).handler((event, data) -> { + StoredEntityData entityData = storedEntityData(event); + ChestedHorseStorage storage = entityData.get(ChestedHorseStorage.class); int index = event.index(); // Store them for later (: switch (index) { case 16 -> { - storage.setLiamaStrength((int) meta.getValue()); + storage.setLiamaStrength((int) data.getValue()); event.cancel(); } case 17 -> { - storage.setLiamaCarpetColor((int) meta.getValue()); + storage.setLiamaCarpetColor((int) data.getValue()); event.cancel(); } case 18 -> { - storage.setLiamaVariant((int) meta.getValue()); + storage.setLiamaVariant((int) data.getValue()); event.cancel(); } } @@ -309,13 +309,13 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { - if ((int) meta.getValue() == 5) { - meta.setValue(0); + filter().type(EntityTypes1_11.EntityType.VILLAGER).index(13).handler((event, data) -> { + if ((int) data.getValue() == 5) { + data.setValue(0); } }); - // handle new Shulker color meta + // handle new Shulker color data filter().type(EntityTypes1_11.EntityType.SHULKER).cancel(15); } @@ -325,7 +325,7 @@ public class EntityPacketRewriter1_11 extends LegacyEntityRewriter { - if (meta.dataType().type().equals(Types.ITEM1_8)) // Is Item - meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue())); + protocol.getEntityRewriter().filter().handler((event, data) -> { + if (data.dataType().type().equals(Types.ITEM1_8)) // Is Item + data.setValue(handleItemToClient(event.user(), (Item) data.getValue())); }); protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_COMMAND, new PacketHandlers() { 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 561542af..2c9020d0 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 @@ -83,12 +83,12 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter storage.add(new EntityData(12, EntityDataTypes1_12.BYTE, (byte) 0x00))); + mapEntityTypeWithData(EntityTypes1_12.EntityType.PARROT, EntityTypes1_12.EntityType.BAT).plainName().spawnEntityData(storage -> storage.add(new EntityData(12, EntityDataTypes1_12.BYTE, (byte) 0x00))); mapEntityTypeWithData(EntityTypes1_12.EntityType.ILLUSIONER, EntityTypes1_12.EntityType.EVOKER).plainName(); - filter().handler((event, meta) -> { - if (meta.dataType() == EntityDataTypes1_12.COMPONENT) { - protocol.getComponentRewriter().processText(event.user(), (JsonElement) meta.getValue()); + filter().handler((event, data) -> { + if (data.dataType() == EntityDataTypes1_12.COMPONENT) { + protocol.getComponentRewriter().processText(event.user(), (JsonElement) data.getValue()); } }); // Handle Illager filter().type(EntityTypes1_12.EntityType.EVOKER).removeIndex(12); - filter().type(EntityTypes1_12.EntityType.ILLUSIONER).index(0).handler((event, meta) -> { - byte mask = (byte) meta.getValue(); + filter().type(EntityTypes1_12.EntityType.ILLUSIONER).index(0).handler((event, data) -> { + byte mask = (byte) data.getValue(); if ((mask & 0x20) == 0x20) { mask &= ~0x20; } - meta.setValue(mask); + data.setValue(mask); }); // Create Parrot storage - filter().type(EntityTypes1_12.EntityType.PARROT).handler((event, meta) -> { - StoredEntityData data = storedEntityData(event); - if (!data.has(ParrotStorage.class)) { - data.put(new ParrotStorage()); + filter().type(EntityTypes1_12.EntityType.PARROT).handler((event, data) -> { + StoredEntityData entityData = storedEntityData(event); + if (!entityData.has(ParrotStorage.class)) { + entityData.put(new ParrotStorage()); } }); - // Parrot remove animal metadata + // Parrot remove animal entity data filter().type(EntityTypes1_12.EntityType.PARROT).cancel(12); // Is baby - filter().type(EntityTypes1_12.EntityType.PARROT).index(13).handler((event, meta) -> { - StoredEntityData data = storedEntityData(event); - ParrotStorage storage = data.get(ParrotStorage.class); - boolean isSitting = (((byte) meta.getValue()) & 0x01) == 0x01; - boolean isTamed = (((byte) meta.getValue()) & 0x04) == 0x04; + filter().type(EntityTypes1_12.EntityType.PARROT).index(13).handler((event, data) -> { + StoredEntityData entityData = storedEntityData(event); + ParrotStorage storage = entityData.get(ParrotStorage.class); + boolean isSitting = (((byte) data.getValue()) & 0x01) == 0x01; + boolean isTamed = (((byte) data.getValue()) & 0x04) == 0x04; if (!storage.isTamed() && isTamed) { // TODO do something to let the user know it's done @@ -231,11 +231,11 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter { - CompoundTag tag = (CompoundTag) meta.getValue(); + filter().type(EntityTypes1_12.EntityType.PLAYER).index(15).handler((event, data) -> { + CompoundTag tag = (CompoundTag) data.getValue(); ShoulderTracker tracker = event.user().get(ShoulderTracker.class); if (tag.isEmpty() && tracker.getLeftShoulder() != null) { @@ -264,7 +264,7 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter { + filter().type(EntityTypes1_12.EntityType.PLAYER).index(16).handler((event, data) -> { CompoundTag tag = (CompoundTag) event.data().getValue(); ShoulderTracker tracker = event.user().get(ShoulderTracker.class); 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 c376edd9..b63a5bad 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 @@ -91,15 +91,15 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter { - List metadata = wrapper.get(Types1_13.ENTITY_DATA_LIST, 0); - handleEntityData(wrapper.get(Types.VAR_INT, 0), metadata, wrapper.user()); + List entityDataList = wrapper.get(Types1_13.ENTITY_DATA_LIST, 0); + handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user()); }); } }); @@ -114,9 +114,9 @@ public class EntityPacketRewriter1_13_1 extends LegacyEntityRewriter { - if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.itemType) { - protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue()); - } else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalBlockStateType) { + filter().handler((event, data) -> { + if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.itemType) { + protocol.getItemRewriter().handleItemToClient(event.user(), (Item) data.getValue()); + } else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalBlockStateType) { // Convert to new block id - int data = (int) meta.getValue(); - meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.particleType) { - rewriteParticle(event.user(), (Particle) meta.getValue()); - } else if (meta.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalComponentType || meta.dataType() == Types1_13.ENTITY_DATA_TYPES.componentType) { - JsonElement element = meta.value(); + int value = (int) data.getValue(); + data.setValue(protocol.getMappingData().getNewBlockStateId(value)); + } else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.particleType) { + rewriteParticle(event.user(), (Particle) data.getValue()); + } else if (data.dataType() == Types1_13.ENTITY_DATA_TYPES.optionalComponentType || data.dataType() == Types1_13.ENTITY_DATA_TYPES.componentType) { + JsonElement element = data.value(); protocol.translatableRewriter().processText(event.user(), element); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java index e0854256..c77eed48 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_13_2to1_13_1/rewriter/EntityPacketRewriter1_13_2.java @@ -45,11 +45,11 @@ public class EntityPacketRewriter1_13_2 { map(Types.SHORT); // 9 - Velocity X map(Types.SHORT); // 10 - Velocity Y map(Types.SHORT); // 11 - Velocity Z - map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 12 - Metadata + map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 12 - Entity data handler(wrapper -> { - for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { - metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId())); + for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { + entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId())); } }); } @@ -65,11 +65,11 @@ public class EntityPacketRewriter1_13_2 { map(Types.DOUBLE); // 4 - Z map(Types.BYTE); // 5 - Yaw map(Types.BYTE); // 6 - Pitch - map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 7 - Metadata + map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 7 - Entity data handler(wrapper -> { - for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { - metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId())); + for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { + entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId())); } }); } @@ -79,11 +79,11 @@ public class EntityPacketRewriter1_13_2 { @Override public void register() { map(Types.VAR_INT); // 0 - Entity ID - map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 1 - Metadata list + map(Types1_13_2.ENTITY_DATA_LIST, Types1_13.ENTITY_DATA_LIST); // 1 - Entity data list handler(wrapper -> { - for (EntityData metadata : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { - metadata.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(metadata.dataType().typeId())); + for (EntityData entityData : wrapper.get(Types1_13.ENTITY_DATA_LIST, 0)) { + entityData.setDataType(Types1_13.ENTITY_DATA_TYPES.byId(entityData.dataType().typeId())); } }); } 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 3f2f9869..0d9bc3ef 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 @@ -145,7 +145,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter { + mapEntityTypeWithData(EntityTypes1_13.EntityType.PHANTOM, EntityTypes1_13.EntityType.PARROT).plainName().spawnEntityData(storage -> { // The phantom is grey/blue so let's do yellow/blue storage.add(new EntityData(15, EntityDataTypes1_12.VAR_INT, 3)); }); @@ -269,32 +269,32 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter { - int typeId = meta.dataType().typeId(); + // Rewrite Data types + filter().handler((event, data) -> { + int typeId = data.dataType().typeId(); if (typeId == 4) { - JsonElement element = meta.value(); + JsonElement element = data.value(); protocol.translatableRewriter().processText(event.user(), element); - meta.setDataType(EntityDataTypes1_12.COMPONENT); + data.setDataType(EntityDataTypes1_12.COMPONENT); } else if (typeId == 5) { // Rewrite optional chat to string - JsonElement element = meta.value(); - meta.setTypeAndValue(EntityDataTypes1_12.STRING, protocol.jsonToLegacy(event.user(), element)); + JsonElement element = data.value(); + data.setTypeAndValue(EntityDataTypes1_12.STRING, protocol.jsonToLegacy(event.user(), element)); } else if (typeId == 6) { - Item item = (Item) meta.getValue(); - meta.setTypeAndValue(EntityDataTypes1_12.ITEM, protocol.getItemRewriter().handleItemToClient(event.user(), item)); + Item item = (Item) data.getValue(); + data.setTypeAndValue(EntityDataTypes1_12.ITEM, protocol.getItemRewriter().handleItemToClient(event.user(), item)); } else if (typeId == 15) { // Discontinue particles event.cancel(); } else { - meta.setDataType(EntityDataTypes1_12.byId(typeId > 5 ? typeId - 1 : typeId)); + data.setDataType(EntityDataTypes1_12.byId(typeId > 5 ? typeId - 1 : typeId)); } }); - // Handle zombie metadata + // Handle zombie entity data filter().type(EntityTypes1_13.EntityType.ZOMBIE).removeIndex(15); - // Handle turtle metadata (Remove them all for now) + // Handle turtle entity data (Remove them all for now) filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(13); // Home pos filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(14); // Has egg filter().type(EntityTypes1_13.EntityType.TURTLE).cancel(15); // Laying egg @@ -302,7 +302,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter { - meta.setValue(15 - (int) meta.getValue()); + filter().type(EntityTypes1_13.EntityType.WOLF).index(17).handler((event, data) -> { + data.setValue(15 - (int) data.getValue()); }); // Rewrite AreaEffectCloud - filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, meta) -> { - Particle particle = (Particle) meta.getValue(); + filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, data) -> { + Particle particle = (Particle) data.getValue(); - ParticleIdMappings1_12_2.ParticleData data = ParticleIdMappings1_12_2.getMapping(particle.id()); + ParticleIdMappings1_12_2.ParticleData particleData = ParticleIdMappings1_12_2.getMapping(particle.id()); int firstArg = 0; int secondArg = 0; - int[] particleArgs = data.rewriteMeta(protocol, particle.getArguments()); + int[] particleArgs = particleData.rewriteMeta(protocol, particle.getArguments()); if (particleArgs != null && particleArgs.length != 0) { - if (data.getHandler().isBlockHandler() && particleArgs[0] == 0) { + if (particleData.getHandler().isBlockHandler() && particleArgs[0] == 0) { // Air doesn't have a break particle for sub 1.13 clients -> glass pane particleArgs[0] = 102; } @@ -339,7 +339,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter { int entityId = wrapper.get(Types.VAR_INT, 0); @@ -79,13 +79,13 @@ public class EntityPacketRewriter1_14_1 extends LegacyEntityRewriter metadata = wrapper.get(Types1_14.ENTITY_DATA_LIST, 0); - handleEntityData(entityId, metadata, wrapper.user()); + List entityDataList = wrapper.get(Types1_14.ENTITY_DATA_LIST, 0); + handleEntityData(entityId, entityDataList, wrapper.user()); }); } }); - // Entity Metadata + // Entity data registerSetEntityData(ClientboundPackets1_14.SET_ENTITY_DATA, Types1_14.ENTITY_DATA_LIST); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java index 287e929a..db874a78 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/BlockItemPacketRewriter1_14.java @@ -242,9 +242,9 @@ public class BlockItemPacketRewriter1_14 extends BackwardsItemRewriter metadataList = new ArrayList<>(); - metadataList.add(new EntityData(16, Types1_13_2.ENTITY_DATA_TYPES.varIntType, armorType)); - wrapper.write(Types1_13.ENTITY_DATA_LIST, metadataList); + List entityDataList = new ArrayList<>(); + entityDataList.add(new EntityData(16, Types1_13_2.ENTITY_DATA_TYPES.varIntType, armorType)); + wrapper.write(Types1_13.ENTITY_DATA_LIST, entityDataList); } }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java index fb18f3e6..4ca7f9f7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_14to1_13_2/rewriter/EntityPacketRewriter1_14.java @@ -193,7 +193,7 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { int type = wrapper.get(Types.VAR_INT, 1); @@ -214,7 +214,7 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter positionHandler.cacheEntityPosition(wrapper, true, false)); } }); @@ -323,14 +323,14 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { - int typeId = meta.dataType().typeId(); + filter().handler((event, data) -> { + int typeId = data.dataType().typeId(); if (typeId <= 15) { - meta.setDataType(Types1_13_2.ENTITY_DATA_TYPES.byId(typeId)); + data.setDataType(Types1_13_2.ENTITY_DATA_TYPES.byId(typeId)); } }); - registerMetaTypeHandler(Types1_13_2.ENTITY_DATA_TYPES.itemType, null, Types1_13_2.ENTITY_DATA_TYPES.optionalBlockStateType, null, + registerEntityDataTypeHandler(Types1_13_2.ENTITY_DATA_TYPES.itemType, null, Types1_13_2.ENTITY_DATA_TYPES.optionalBlockStateType, null, Types1_13_2.ENTITY_DATA_TYPES.componentType, Types1_13_2.ENTITY_DATA_TYPES.optionalComponentType); filter().type(EntityTypes1_14.PILLAGER).cancel(15); @@ -353,15 +353,15 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { - rewriteParticle(event.user(), (Particle) meta.getValue()); + filter().type(EntityTypes1_14.AREA_EFFECT_CLOUD).index(10).handler((event, data) -> { + rewriteParticle(event.user(), (Particle) data.getValue()); }); - filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> { - meta.setDataType(Types1_13_2.ENTITY_DATA_TYPES.varIntType); - Integer value = (Integer) meta.getValue(); + filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, data) -> { + data.setDataType(Types1_13_2.ENTITY_DATA_TYPES.varIntType); + Integer value = (Integer) data.getValue(); if (value == null) { - meta.setValue(0); + data.setValue(0); } }); @@ -369,10 +369,10 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { - VillagerData villagerData = (VillagerData) meta.getValue(); - meta.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, villagerDataToProfession(villagerData)); - if (meta.id() == 16) { + EntityDataHandler villagerDataHandler = (event, data) -> { + VillagerData villagerData = (VillagerData) data.getValue(); + data.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, villagerDataToProfession(villagerData)); + if (data.id() == 16) { event.setIndex(15); // decreased by 2 again in one of the following handlers } }; @@ -381,14 +381,14 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { - byte value = (byte) meta.getValue(); + filter().type(EntityTypes1_14.ABSTRACT_SKELETON).index(13).handler((event, data) -> { + byte value = (byte) data.getValue(); if ((value & 4) != 0) { event.createExtraData(new EntityData(14, Types1_13_2.ENTITY_DATA_TYPES.booleanType, true)); } }); - filter().type(EntityTypes1_14.ZOMBIE).index(13).handler((event, meta) -> { - byte value = (byte) meta.getValue(); + filter().type(EntityTypes1_14.ZOMBIE).index(13).handler((event, data) -> { + byte value = (byte) data.getValue(); if ((value & 4) != 0) { event.createExtraData(new EntityData(16, Types1_13_2.ENTITY_DATA_TYPES.booleanType, true)); } @@ -397,10 +397,10 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { + filter().type(EntityTypes1_14.LIVING_ENTITY).handler((event, data) -> { int index = event.index(); if (index == 12) { - BlockPosition position = (BlockPosition) meta.getValue(); + BlockPosition position = (BlockPosition) data.getValue(); if (position != null) { // Use bed PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.PLAYER_SLEEP, null, event.user()); @@ -423,51 +423,49 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter { + filter().type(EntityTypes1_14.OCELOT).index(13).handler((event, data) -> { event.setIndex(15); - meta.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, 0); + data.setTypeAndValue(Types1_13_2.ENTITY_DATA_TYPES.varIntType, 0); }); - filter().type(EntityTypes1_14.CAT).handler((event, meta) -> { + filter().type(EntityTypes1_14.CAT).handler((event, data) -> { if (event.index() == 15) { - meta.setValue(1); + data.setValue(1); } else if (event.index() == 13) { - meta.setValue((byte) ((byte) meta.getValue() & 0x4)); + data.setValue((byte) ((byte) data.getValue() & 0x4)); } }); - filter().handler((event, meta) -> { - if (meta.dataType().typeId() > 15) { - throw new IllegalArgumentException("Unhandled metadata: " + meta); + filter().handler((event, data) -> { + if (data.dataType().typeId() > 15) { + throw new IllegalArgumentException("Unhandled entity data: " + data); } }); } public int villagerDataToProfession(VillagerData data) { - switch (data.profession()) { - case 1: // Armorer - case 10: // Mason - case 13: // Toolsmith - case 14: // Weaponsmith - return 3; // Blacksmith - case 2: // Butcher - case 8: // Leatherworker - return 4; // Butcher - case 3: // Cartographer - case 9: // Librarian - return 1; // Librarian - case 4: // Cleric - return 2; // Priest - case 5: // Farmer - case 6: // Fisherman - case 7: // Fletcher - case 12: // Shepherd - return 0; // Farmer - case 0: // None - case 11: // Nitwit - default: - return 5; // Nitwit - } + return switch (data.profession()) { // Armorer + // Mason + // Toolsmith + case 1, 10, 13, 14 -> // Weaponsmith + 3; // Blacksmith + // Butcher + case 2, 8 -> // Leatherworker + 4; // Butcher + // Cartographer + case 3, 9 -> // Librarian + 1; // Librarian + case 4 -> // Cleric + 2; // Priest + // Farmer + // Fisherman + // Fletcher + case 5, 6, 7, 12 -> // Shepherd + 0; // Farmer + // None + // Nitwit + default -> 5; // Nitwit + }; } @Override diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/rewriter/EntityPacketRewriter1_15.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/rewriter/EntityPacketRewriter1_15.java index 6dccd55b..45eb30c7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/rewriter/EntityPacketRewriter1_15.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_15to1_14_4/rewriter/EntityPacketRewriter1_15.java @@ -80,7 +80,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one + handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Entity data is no longer sent in 1.15, so we have to send an empty one handler(wrapper -> { int type = wrapper.get(Types.VAR_INT, 1); @@ -136,7 +136,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Metadata is no longer sent in 1.15, so we have to send an empty one + handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Entity data is no longer sent in 1.15, so we have to send an empty one handler(getTrackerHandler(EntityTypes1_15.PLAYER, Types.VAR_INT)); } @@ -191,7 +191,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter { + filter().type(EntityTypes1_15.WOLF).index(8).handler((event, data) -> { event.createExtraData(new EntityData(17/*WOLF_HEALTH*/, Types1_14.ENTITY_DATA_TYPES.floatType, event.data().value())); }); } @@ -213,7 +213,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter { + mapEntityTypeWithData(EntityTypes1_15.BEE, EntityTypes1_15.PUFFERFISH).jsonName().spawnEntityData(storage -> { storage.add(new EntityData(14, Types1_14.ENTITY_DATA_TYPES.booleanType, false)); storage.add(new EntityData(15, Types1_14.ENTITY_DATA_TYPES.varIntType, 2)); }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java index c35fd8b4..1721b191 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_16_2to1_16_1/rewriter/EntityPacketRewriter1_16_2.java @@ -120,7 +120,7 @@ public class EntityPacketRewriter1_16_2 extends EntityRewriter { - meta.setDataType(Types1_14.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); + filter().handler((event, data) -> { + data.setDataType(Types1_14.ENTITY_DATA_TYPES.byId(data.dataType().typeId())); - EntityDataType type = meta.dataType(); + EntityDataType type = data.dataType(); if (type == Types1_14.ENTITY_DATA_TYPES.itemType) { - meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue())); + data.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) data.getValue())); } else if (type == Types1_14.ENTITY_DATA_TYPES.optionalBlockStateType) { - meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue())); + data.setValue(protocol.getMappingData().getNewBlockStateId((int) data.getValue())); } else if (type == Types1_14.ENTITY_DATA_TYPES.particleType) { - rewriteParticle(event.user(), (Particle) meta.getValue()); + rewriteParticle(event.user(), (Particle) data.getValue()); } else if (type == Types1_14.ENTITY_DATA_TYPES.optionalComponentType) { - JsonElement text = meta.value(); + JsonElement text = data.value(); if (text != null) { protocol.getComponentRewriter().processText(event.user(), text); } @@ -255,9 +255,9 @@ public class EntityPacketRewriter1_16 extends EntityRewriter { - boolean baby = meta.value(); - meta.setTypeAndValue(Types1_14.ENTITY_DATA_TYPES.varIntType, baby ? 1 : 3); + filter().type(EntityTypes1_16.STRIDER).index(15).handler((event, data) -> { + boolean baby = data.value(); + data.setTypeAndValue(Types1_14.ENTITY_DATA_TYPES.varIntType, baby ? 1 : 3); }); filter().type(EntityTypes1_16.STRIDER).cancel(16); filter().type(EntityTypes1_16.STRIDER).cancel(17); @@ -266,29 +266,29 @@ public class EntityPacketRewriter1_16 extends EntityRewriter { + filter().type(EntityTypes1_16.ABSTRACT_ARROW).handler((event, data) -> { if (event.index() >= 8) { event.setIndex(event.index() + 1); } }); - filter().type(EntityTypes1_16.WOLF).index(16).handler((event, meta) -> { - byte mask = meta.value(); - StoredEntityData data = tracker(event.user()).entityData(event.entityId()); - data.put(new WolfDataMaskStorage(mask)); + filter().type(EntityTypes1_16.WOLF).index(16).handler((event, data) -> { + byte mask = data.value(); + StoredEntityData entityData = tracker(event.user()).entityData(event.entityId()); + entityData.put(new WolfDataMaskStorage(mask)); }); - filter().type(EntityTypes1_16.WOLF).index(20).handler((event, meta) -> { - StoredEntityData data = tracker(event.user()).entityDataIfPresent(event.entityId()); + filter().type(EntityTypes1_16.WOLF).index(20).handler((event, data) -> { + StoredEntityData entityData = tracker(event.user()).entityDataIfPresent(event.entityId()); byte previousMask = 0; - if (data != null) { - WolfDataMaskStorage wolfData = data.get(WolfDataMaskStorage.class); + if (entityData != null) { + WolfDataMaskStorage wolfData = entityData.get(WolfDataMaskStorage.class); if (wolfData != null) { previousMask = wolfData.tameableMask(); } } - int angerTime = meta.value(); + int angerTime = data.value(); byte tameableMask = (byte) (angerTime > 0 ? previousMask | 2 : previousMask & -3); event.createExtraData(new EntityData(16, Types1_14.ENTITY_DATA_TYPES.byteType, tameableMask)); event.cancel(); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java index 92801139..b0fe1a63 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/EntityPacketRewriter1_17.java @@ -145,12 +145,12 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter { - meta.setDataType(Types1_16.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); + filter().handler((event, data) -> { + data.setDataType(Types1_16.ENTITY_DATA_TYPES.byId(data.dataType().typeId())); - EntityDataType type = meta.dataType(); + EntityDataType type = data.dataType(); if (type == Types1_16.ENTITY_DATA_TYPES.particleType) { - Particle particle = (Particle) meta.getValue(); + Particle particle = (Particle) data.getValue(); if (particle.id() == 16) { // Dust / Dust Transition // Remove transition target color values 4-6 particle.getArguments().subList(4, 7).clear(); @@ -164,17 +164,17 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter 6) { - meta.setValue(pose - 1); + data.setValue(pose - 1); } } }); // Particles have already been handled - registerMetaTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, null, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, null, + registerEntityDataTypeHandler(Types1_16.ENTITY_DATA_TYPES.itemType, null, Types1_16.ENTITY_DATA_TYPES.optionalBlockStateType, null, Types1_16.ENTITY_DATA_TYPES.componentType, Types1_16.ENTITY_DATA_TYPES.optionalComponentType); filter().type(EntityTypes1_17.AXOLOTL).cancel(17); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java index 3c796c3c..685ec209 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_18to1_17_1/rewriter/EntityPacketRewriter1_18.java @@ -24,7 +24,6 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17; import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_17; import com.viaversion.viaversion.api.type.types.version.Types1_18; @@ -32,7 +31,6 @@ import com.viaversion.viaversion.protocols.v1_17_1to1_18.packet.ClientboundPacke import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.ListTag; import com.viaversion.nbt.tag.StringTag; -import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.util.TagUtil; public final class EntityPacketRewriter1_18 extends EntityRewriter { @@ -94,15 +92,15 @@ public final class EntityPacketRewriter1_18 extends EntityRewriter { - meta.setDataType(Types1_17.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); + filter().handler((event, data) -> { + data.setDataType(Types1_17.ENTITY_DATA_TYPES.byId(data.dataType().typeId())); - EntityDataType type = meta.dataType(); + EntityDataType type = data.dataType(); if (type == Types1_17.ENTITY_DATA_TYPES.particleType) { - Particle particle = meta.value(); + Particle particle = data.value(); if (particle.id() == 3) { // Block marker - Particle.ParticleData data = particle.getArguments().remove(0); - int blockState = (int) data.getValue(); + Particle.ParticleData value = particle.getArguments().remove(0); + int blockState = (int) value.getValue(); if (blockState == 7786) { // Light block particle.setId(3); } else { @@ -117,7 +115,7 @@ public final class EntityPacketRewriter1_18 extends EntityRewriter { - final int id = meta.dataType().typeId(); + filter().handler((event, data) -> { + final int id = data.dataType().typeId(); if (id > 2) { - meta.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id - 1)); // long added + data.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id - 1)); // long added } else if (id != 2) { - meta.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id)); + data.setDataType(Types1_19.ENTITY_DATA_TYPES.byId(id)); } }); - registerMetaTypeHandler(Types1_19.ENTITY_DATA_TYPES.itemType, null, Types1_19.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19.ENTITY_DATA_TYPES.particleType, + registerEntityDataTypeHandler(Types1_19.ENTITY_DATA_TYPES.itemType, null, Types1_19.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19.ENTITY_DATA_TYPES.particleType, Types1_19.ENTITY_DATA_TYPES.componentType, Types1_19.ENTITY_DATA_TYPES.optionalComponentType); registerBlockStateHandler(EntityTypes1_19_3.ABSTRACT_MINECART, 11); - filter().dataType(Types1_19.ENTITY_DATA_TYPES.poseType).handler((event, meta) -> { + filter().dataType(Types1_19.ENTITY_DATA_TYPES.poseType).handler((event, data) -> { // Sitting pose added - final int pose = meta.value(); + final int pose = data.value(); if (pose == 10) { - meta.setValue(0); // Standing + data.setValue(0); // Standing } else if (pose > 10) { - meta.setValue(pose - 1); + data.setValue(pose - 1); } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java index 6564d8e2..eb985ca7 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19_4to1_19_3/rewriter/EntityPacketRewriter1_19_4.java @@ -141,39 +141,39 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter { - int id = meta.dataType().typeId(); + filter().handler((event, data) -> { + int id = data.dataType().typeId(); if (id >= 25) { // Sniffer state, Vector3f, Quaternion types return; } else if (id >= 15) { // Optional block state - just map down to block state id--; } - meta.setDataType(Types1_19_3.ENTITY_DATA_TYPES.byId(id)); + data.setDataType(Types1_19_3.ENTITY_DATA_TYPES.byId(id)); }); - registerMetaTypeHandler(Types1_19_3.ENTITY_DATA_TYPES.itemType, null, Types1_19_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_3.ENTITY_DATA_TYPES.particleType, + registerEntityDataTypeHandler(Types1_19_3.ENTITY_DATA_TYPES.itemType, null, Types1_19_3.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_19_3.ENTITY_DATA_TYPES.particleType, Types1_19_3.ENTITY_DATA_TYPES.componentType, Types1_19_3.ENTITY_DATA_TYPES.optionalComponentType); registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11); - filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, meta) -> { - final int boatType = meta.value(); + filter().type(EntityTypes1_19_4.BOAT).index(11).handler((event, data) -> { + final int boatType = data.value(); if (boatType > 4) { // Cherry - meta.setValue(boatType - 1); + data.setValue(boatType - 1); } }); - filter().type(EntityTypes1_19_4.TEXT_DISPLAY).index(22).handler(((event, meta) -> { + filter().type(EntityTypes1_19_4.TEXT_DISPLAY).index(22).handler(((event, data) -> { // Send as custom display name event.setIndex(2); - meta.setDataType(Types1_19_3.ENTITY_DATA_TYPES.optionalComponentType); + data.setDataType(Types1_19_3.ENTITY_DATA_TYPES.optionalComponentType); event.createExtraData(new EntityData(3, Types1_19_3.ENTITY_DATA_TYPES.booleanType, true)); // Show custom name - final JsonElement element = meta.value(); + final JsonElement element = data.value(); protocol.getComponentRewriter().processText(event.user(), element); })); - filter().type(EntityTypes1_19_4.DISPLAY).handler((event, meta) -> { + filter().type(EntityTypes1_19_4.DISPLAY).handler((event, data) -> { // TODO Maybe spawn an extra entity to ride the armor stand for blocks and items - // Remove a large heap of display metadata + // Remove a large heap of display entity data if (event.index() > 7) { event.cancel(); } @@ -193,16 +193,16 @@ public final class EntityPacketRewriter1_19_4 extends EntityRewriter { + final EntityReplacement.EntityDataCreator displayDataCreator = storage -> { storage.add(new EntityData(0, Types1_19_3.ENTITY_DATA_TYPES.byteType, (byte) 0x20)); // Invisible storage.add(new EntityData(5, Types1_19_3.ENTITY_DATA_TYPES.booleanType, true)); // No gravity storage.add(new EntityData(15, Types1_19_3.ENTITY_DATA_TYPES.byteType, (byte) (0x01 | 0x10))); // Small marker }; - mapEntityTypeWithData(EntityTypes1_19_4.TEXT_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); - mapEntityTypeWithData(EntityTypes1_19_4.ITEM_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); - mapEntityTypeWithData(EntityTypes1_19_4.BLOCK_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); + mapEntityTypeWithData(EntityTypes1_19_4.TEXT_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator); + mapEntityTypeWithData(EntityTypes1_19_4.ITEM_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator); + mapEntityTypeWithData(EntityTypes1_19_4.BLOCK_DISPLAY, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator); - mapEntityTypeWithData(EntityTypes1_19_4.INTERACTION, EntityTypes1_19_4.ARMOR_STAND).spawnMetadata(displayMetaCreator); // Not much we can do about this one + mapEntityTypeWithData(EntityTypes1_19_4.INTERACTION, EntityTypes1_19_4.ARMOR_STAND).spawnEntityData(displayDataCreator); // Not much we can do about this one mapEntityTypeWithData(EntityTypes1_19_4.SNIFFER, EntityTypes1_19_4.RAVAGER).jsonName(); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/EntityPacketRewriter1_19.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/EntityPacketRewriter1_19.java index cc769b28..76d08a2d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/EntityPacketRewriter1_19.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_19to1_18_2/rewriter/EntityPacketRewriter1_19.java @@ -84,7 +84,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter { - if (meta.dataType().typeId() <= Types1_18.ENTITY_DATA_TYPES.poseType.typeId()) { - meta.setDataType(Types1_18.ENTITY_DATA_TYPES.byId(meta.dataType().typeId())); + filter().handler((event, data) -> { + if (data.dataType().typeId() <= Types1_18.ENTITY_DATA_TYPES.poseType.typeId()) { + data.setDataType(Types1_18.ENTITY_DATA_TYPES.byId(data.dataType().typeId())); } - final EntityDataType type = meta.dataType(); + final EntityDataType type = data.dataType(); if (type == Types1_18.ENTITY_DATA_TYPES.particleType) { - final Particle particle = (Particle) meta.getValue(); + final Particle particle = (Particle) data.getValue(); final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); if (particle.id() == particleMappings.id("sculk_charge")) { //TODO @@ -272,19 +272,19 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter= 8) { // Croaking, using_tongue, roaring, sniffing, emerging, digging -> standing -> standing - meta.setValue(0); + data.setValue(0); } } }); - registerMetaTypeHandler(Types1_18.ENTITY_DATA_TYPES.itemType, null, Types1_18.ENTITY_DATA_TYPES.optionalBlockStateType, null, + registerEntityDataTypeHandler(Types1_18.ENTITY_DATA_TYPES.itemType, null, Types1_18.ENTITY_DATA_TYPES.optionalBlockStateType, null, Types1_18.ENTITY_DATA_TYPES.componentType, Types1_18.ENTITY_DATA_TYPES.optionalComponentType); registerBlockStateHandler(EntityTypes1_19.ABSTRACT_MINECART, 11); - filter().type(EntityTypes1_19.PAINTING).index(8).handler((event, meta) -> { + filter().type(EntityTypes1_19.PAINTING).index(8).handler((event, data) -> { event.cancel(); final StoredEntityData entityData = tracker(event.user()).entityDataIfPresent(event.entityId()); @@ -293,7 +293,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter meta.setDataType(Types1_18.ENTITY_DATA_TYPES.varIntType)); + filter().type(EntityTypes1_19.CAT).index(19).handler((event, data) -> data.setDataType(Types1_18.ENTITY_DATA_TYPES.varIntType)); filter().type(EntityTypes1_19.FROG).cancel(16); // Age filter().type(EntityTypes1_19.FROG).cancel(17); // Variant diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java index 4e64527e..d4445f65 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_2to1_20/rewriter/EntityPacketRewriter1_20_2.java @@ -198,8 +198,8 @@ public final class EntityPacketRewriter1_20_2 extends EntityRewriter meta.setDataType(Types1_20.ENTITY_DATA_TYPES.byId(meta.dataType().typeId()))); - registerMetaTypeHandler(Types1_20.ENTITY_DATA_TYPES.itemType, Types1_20.ENTITY_DATA_TYPES.blockStateType, Types1_20.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20.ENTITY_DATA_TYPES.particleType, null, null); + filter().handler((event, data) -> data.setDataType(Types1_20.ENTITY_DATA_TYPES.byId(data.dataType().typeId()))); + registerEntityDataTypeHandler(Types1_20.ENTITY_DATA_TYPES.itemType, Types1_20.ENTITY_DATA_TYPES.blockStateType, Types1_20.ENTITY_DATA_TYPES.optionalBlockStateType, Types1_20.ENTITY_DATA_TYPES.particleType, null, null); registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11); filter().type(EntityTypes1_19_4.DISPLAY).removeIndex(10); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java index ed0583c6..fae069b5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_3to1_20_2/rewriter/EntityPacketRewriter1_20_3.java @@ -96,16 +96,16 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter { - final EntityDataType type = meta.dataType(); + filter().handler((event, data) -> { + final EntityDataType type = data.dataType(); if (type == Types1_20_3.ENTITY_DATA_TYPES.componentType) { - meta.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.componentType, ComponentUtil.tagToJson(meta.value())); + data.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.componentType, ComponentUtil.tagToJson(data.value())); return; } else if (type == Types1_20_3.ENTITY_DATA_TYPES.optionalComponentType) { - meta.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.optionalComponentType, ComponentUtil.tagToJson(meta.value())); + data.setTypeAndValue(Types1_20_2.ENTITY_DATA_TYPES.optionalComponentType, ComponentUtil.tagToJson(data.value())); return; } else if (type == Types1_20_3.ENTITY_DATA_TYPES.particleType) { - final Particle particle = (Particle) meta.getValue(); + final Particle particle = (Particle) data.getValue(); final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings(); if (particle.id() == particleMappings.id("vibration")) { // Change the type of the position source type argument @@ -117,16 +117,16 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter= 15) { event.cancel(); } } - meta.setDataType(Types1_20_2.ENTITY_DATA_TYPES.byId(type.typeId())); + data.setDataType(Types1_20_2.ENTITY_DATA_TYPES.byId(type.typeId())); }); - registerMetaTypeHandler( + registerEntityDataTypeHandler( Types1_20_2.ENTITY_DATA_TYPES.itemType, Types1_20_2.ENTITY_DATA_TYPES.blockStateType, Types1_20_2.ENTITY_DATA_TYPES.optionalBlockStateType, diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index da95048c..23969bf9 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -372,9 +372,9 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter metadataList = new ArrayList<>(); - metadataList.add(new EntityData(20, Types1_20_3.ENTITY_DATA_TYPES.varIntType, color)); - setEntityData.write(Types1_20_3.ENTITY_DATA_LIST, metadataList); + final List entityDataList = new ArrayList<>(); + entityDataList.add(new EntityData(20, Types1_20_3.ENTITY_DATA_TYPES.varIntType, color)); + setEntityData.write(Types1_20_3.ENTITY_DATA_LIST, entityDataList); setEntityData.send(Protocol1_20_5To1_20_3.class); } @@ -408,7 +408,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { - final Particle particle = meta.value(); + filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).index(11).handler((event, data) -> { + final Particle particle = data.value(); if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) { - // Move color to its own metadata + // Move color to its own entity data final int color = particle.removeArgument(0).getValue(); event.createExtraData(new EntityData(9, Types1_20_3.ENTITY_DATA_TYPES.varIntType, removeAlpha(color))); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/EntityPacketRewriter1_20.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/EntityPacketRewriter1_20.java index 353e0c93..69dc6fec 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/EntityPacketRewriter1_20.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_20to1_19_4/rewriter/EntityPacketRewriter1_20.java @@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; -import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_19_4; import com.viaversion.viaversion.api.type.types.version.Types1_20; @@ -33,7 +32,6 @@ import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPac import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.ListTag; import com.viaversion.nbt.tag.StringTag; -import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.util.Key; import java.util.Set; @@ -124,13 +122,13 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter meta.setDataType(Types1_19_4.ENTITY_DATA_TYPES.byId(meta.dataType().typeId()))); - registerMetaTypeHandler(Types1_19_4.ENTITY_DATA_TYPES.itemType, Types1_19_4.ENTITY_DATA_TYPES.blockStateType, Types1_19_4.ENTITY_DATA_TYPES.optionalBlockStateType, + filter().handler((event, data) -> data.setDataType(Types1_19_4.ENTITY_DATA_TYPES.byId(data.dataType().typeId()))); + 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, Types1_19_4.ENTITY_DATA_TYPES.componentType, Types1_19_4.ENTITY_DATA_TYPES.optionalComponentType); registerBlockStateHandler(EntityTypes1_19_4.ABSTRACT_MINECART, 11); // Rotate item display by 180 degrees around the Y axis - filter().type(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, meta) -> { + filter().type(EntityTypes1_19_4.ITEM_DISPLAY).handler((event, data) -> { if (event.trackedEntity().hasSentEntityData() || event.hasExtraData()) { return; } @@ -139,9 +137,9 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter { - final Quaternion quaternion = meta.value(); - meta.setValue(rotateY180(quaternion)); + filter().type(EntityTypes1_19_4.ITEM_DISPLAY).index(12).handler((event, data) -> { + final Quaternion quaternion = data.value(); + data.setValue(rotateY180(quaternion)); }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java index 2cb8149f..98b98000 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/EntityPacketRewriter1_21.java @@ -196,7 +196,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter