From 2d0a597f74f4be540e7c0fff30ed767377ebfa9d Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 26 May 2021 13:04:15 +0200 Subject: [PATCH] Make Metadata fully type safe, remove "Discontinued" meta types The Discontinued entry was a special edge case that could lead to a Metadata type returning null. Instead, just directly use null in the 1.8->1.9 code where it is checked against. Also renamed the Meta1_17Types entries to be in uppercase and properly represent their value type. --- .../api/data/entity/EntityTracker.java | 2 +- .../api/minecraft/metadata/Metadata.java | 45 +++++++++++++------ .../metadata/types/MetaType1_12.java | 3 +- .../metadata/types/MetaType1_13.java | 3 +- .../metadata/types/MetaType1_13_2.java | 3 +- .../metadata/types/MetaType1_14.java | 3 +- .../metadata/types/MetaType1_17.java | 45 +++++++++---------- .../minecraft/metadata/types/MetaType1_8.java | 1 + .../minecraft/metadata/types/MetaType1_9.java | 3 +- .../data/entity/EntityTrackerBase.java | 7 +-- .../metadata/MetadataRewriter1_11To1_10.java | 3 +- .../MetadataRewriter1_13To1_12_2.java | 5 +-- .../MetadataRewriter1_14To1_13_2.java | 6 +-- .../MetadataRewriter1_17To1_16_4.java | 4 +- .../protocol1_9to1_8/metadata/MetaIndex.java | 23 +++++----- .../metadata/MetadataRewriter1_9To1_8.java | 5 +-- 16 files changed, 85 insertions(+), 76 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/entity/EntityTracker.java b/api/src/main/java/com/viaversion/viaversion/api/data/entity/EntityTracker.java index 344a6a84e..c24da722c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/entity/EntityTracker.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/entity/EntityTracker.java @@ -26,7 +26,7 @@ import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import org.checkerframework.checker.nullness.qual.Nullable; -public interface EntityTracker extends ClientEntityIdChangeListener { +public interface EntityTracker { /** * User connection the tracker belongs to. diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java index 69e8f393b..0bb54b28b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java @@ -38,14 +38,12 @@ public final class Metadata { * @param id metadata index * @param metaType metadata type * @param value value if present - * @throws NullPointerException if the given metaType is null * @throws IllegalArgumentException if the value and metaType are incompatible */ public Metadata(int id, MetaType metaType, @Nullable Object value) { - Preconditions.checkNotNull(metaType); this.id = id; this.metaType = metaType; - this.value = checkValue(value); + this.value = checkValue(metaType, value); } public int id() { @@ -61,13 +59,14 @@ public final class Metadata { } /** - * Sets the metadata type. - * Update the value with {@link #setValue(Object)} in case value and type are no longer compatible. + * Sets the metadata type if compatible with the current value. * * @param metaType metadata type + * @throws IllegalArgumentException if the metadata type and current value are incompatible + * @see #setTypeAndValue(MetaType, Object) */ public void setMetaType(MetaType metaType) { - Preconditions.checkNotNull(metaType); + checkValue(metaType, this.value); this.metaType = metaType; } @@ -80,28 +79,46 @@ public final class Metadata { } /** - * Sets the metadata value. - * Always call {@link #setMetaType(MetaType)} first if the output type changes. + * Sets the metadata value if compatible with the current meta type. * * @param value value - * @throws IllegalArgumentException if the value and metaType are incompatible + * @throws IllegalArgumentException if the value and current metaType are incompatible + * @see #setTypeAndValue(MetaType, Object) */ public void setValue(@Nullable Object value) { - this.value = checkValue(value); + this.value = checkValue(this.metaType, value); } - private Object checkValue(Object value) { + /** + * Sets metadata type and value. + * + * @param metaType metadata type + * @param value value + * @throws IllegalArgumentException if the value and metaType are incompatible + */ + public void setTypeAndValue(MetaType metaType, @Nullable Object value) { + this.value = checkValue(metaType, value); + this.metaType = metaType; + } + + private Object checkValue(MetaType metaType, @Nullable Object value) { + Preconditions.checkNotNull(metaType); if (value != null && !metaType.type().getOutputClass().isAssignableFrom(value.getClass())) { - throw new IllegalArgumentException("Metadata value and metaType are incompatible. Type=" + metaType + ", value=" + value); + throw new IllegalArgumentException("Metadata value and metaType are incompatible. Type=" + metaType + + ", value=" + (value != null ? value + " (" + value.getClass().getSimpleName() + ")" : "null")); } return value; } + @Deprecated + public void setMetaTypeUnsafe(MetaType type) { + this.metaType = type; + } + @Override public boolean equals(final Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Metadata metadata = (Metadata) o; if (id != metadata.id) return false; if (metaType != metaType) return false; @@ -111,7 +128,7 @@ public final class Metadata { @Override public int hashCode() { int result = id; - result = 31 * result + (metaType != null ? metaType.hashCode() : 0); + result = 31 * result + metaType.hashCode(); result = 31 * result + (value != null ? value.hashCode() : 0); return result; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_12.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_12.java index d704000d4..fcc32ca88 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_12.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_12.java @@ -39,8 +39,7 @@ public enum MetaType1_12 implements MetaType { Direction(10, Type.VAR_INT), OptUUID(11, Type.OPTIONAL_UUID), BlockID(12, Type.VAR_INT), - NBTTag(13, Type.NBT), - Discontinued(99, null); + NBTTag(13, Type.NBT); private final int typeID; private final Type type; diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java index e5c1bd772..7235e729e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java @@ -42,8 +42,7 @@ public enum MetaType1_13 implements MetaType { OptUUID(12, Type.OPTIONAL_UUID), BlockID(13, Type.VAR_INT), NBTTag(14, Type.NBT), - PARTICLE(15, Types1_13.PARTICLE), - Discontinued(99, null); + PARTICLE(15, Types1_13.PARTICLE); private final int typeID; private final Type type; diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java index 9ea629b16..78081e52d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java @@ -42,8 +42,7 @@ public enum MetaType1_13_2 implements MetaType { OptUUID(12, Type.OPTIONAL_UUID), BlockID(13, Type.VAR_INT), NBTTag(14, Type.NBT), - PARTICLE(15, Types1_13_2.PARTICLE), - Discontinued(99, null); + PARTICLE(15, Types1_13_2.PARTICLE); private final int typeID; private final Type type; diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java index 387d86a55..135205b2d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java @@ -45,8 +45,7 @@ public enum MetaType1_14 implements MetaType { PARTICLE(15, Types1_14.PARTICLE), VillagerData(16, Type.VILLAGER_DATA), OptVarInt(17, Type.OPTIONAL_VAR_INT), - Pose(18, Type.VAR_INT), - Discontinued(99, null); + Pose(18, Type.VAR_INT); private final int typeID; private final Type type; diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java index 0be7e9588..c495b1368 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java @@ -27,32 +27,31 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_17; public enum MetaType1_17 implements MetaType { - Byte(0, Type.BYTE), - VarInt(1, Type.VAR_INT), - Float(2, Type.FLOAT), - String(3, Type.STRING), - Chat(4, Type.COMPONENT), - OptChat(5, Type.OPTIONAL_COMPONENT), - Slot(6, Type.FLAT_VAR_INT_ITEM), - Boolean(7, Type.BOOLEAN), - Vector3F(8, Type.ROTATION), - Position(9, Type.POSITION1_14), - OptPosition(10, Type.OPTIONAL_POSITION_1_14), - Direction(11, Type.VAR_INT), - OptUUID(12, Type.OPTIONAL_UUID), - BlockID(13, Type.VAR_INT), - NBTTag(14, Type.NBT), + BYTE(0, Type.BYTE), + VAR_INT(1, Type.VAR_INT), + FLOAT(2, Type.FLOAT), + STRING(3, Type.STRING), + COMPONENT(4, Type.COMPONENT), + OPT_COMPONENT(5, Type.OPTIONAL_COMPONENT), + ITEM(6, Type.FLAT_VAR_INT_ITEM), + BOOLEAN(7, Type.BOOLEAN), + ROTATION(8, Type.ROTATION), + POSITION(9, Type.POSITION1_14), + OPT_POSITION(10, Type.OPTIONAL_POSITION_1_14), + DIRECTION(11, Type.VAR_INT), + OPT_UUID(12, Type.OPTIONAL_UUID), + BLOCK_STATE(13, Type.VAR_INT), + NBT(14, Type.NBT), PARTICLE(15, Types1_17.PARTICLE), - VillagerData(16, Type.VILLAGER_DATA), - OptVarInt(17, Type.OPTIONAL_VAR_INT), - Pose(18, Type.VAR_INT), - Discontinued(99, null); + VILLAGER_DATA(16, Type.VILLAGER_DATA), + OPT_VAR_INT(17, Type.OPTIONAL_VAR_INT), + POSE(18, Type.VAR_INT); - private final int typeID; + private final int typeId; private final Type type; - MetaType1_17(int typeID, Type type) { - this.typeID = typeID; + MetaType1_17(int typeId, Type type) { + this.typeId = typeId; this.type = type; } @@ -62,7 +61,7 @@ public enum MetaType1_17 implements MetaType { @Override public int typeId() { - return typeID; + return typeId; } @Override diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_8.java index 3693b8eef..f6141b126 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_8.java @@ -34,6 +34,7 @@ public enum MetaType1_8 implements MetaType { Slot(5, Type.ITEM), Position(6, Type.VECTOR), Rotation(7, Type.ROTATION), + @Deprecated NonExistent(-1, Type.NOTHING); private final int typeID; diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_9.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_9.java index de626b340..9d336e02f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_9.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_9.java @@ -38,8 +38,7 @@ public enum MetaType1_9 implements MetaType { OptPosition(9, Type.OPTIONAL_POSITION), Direction(10, Type.VAR_INT), OptUUID(11, Type.OPTIONAL_UUID), - BlockID(12, Type.VAR_INT), - Discontinued(99, null); + BlockID(12, Type.VAR_INT); private final int typeID; private final Type type; diff --git a/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java b/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java index 77ede46f9..76d092c14 100644 --- a/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java +++ b/common/src/main/java/com/viaversion/viaversion/data/entity/EntityTrackerBase.java @@ -20,6 +20,7 @@ package com.viaversion.viaversion.data.entity; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.data.entity.ClientEntityIdChangeListener; import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.minecraft.entities.EntityType; @@ -28,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public class EntityTrackerBase implements EntityTracker { +public class EntityTrackerBase implements EntityTracker, ClientEntityIdChangeListener { private final Map entityTypes = new ConcurrentHashMap<>(); private final Map entityData; private final UserConnection connection; @@ -68,9 +69,9 @@ public class EntityTrackerBase implements EntityTracker { } @Override - public StoredEntityData entityData(int id) { + public @Nullable StoredEntityData entityData(int id) { EntityType type = entityType(id); - return entityData.computeIfAbsent(id, s -> new StoredEntityImpl(type)); + return type != null ? entityData.computeIfAbsent(id, s -> new StoredEntityImpl(type)) : null; } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java index cebf4151d..023d4fed1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_11to1_10/metadata/MetadataRewriter1_11To1_10.java @@ -51,9 +51,8 @@ public class MetadataRewriter1_11To1_10 extends EntityRewriter Chat DisplayName if (metadata.id() == 2) { - metadata.setMetaType(MetaType1_13.OptChat); if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) { - metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue())); + metadata.setTypeAndValue(MetaType1_13.OptChat, ChatRewriter.legacyTextToJson((String) metadata.getValue())); } else { - metadata.setValue(null); + metadata.setTypeAndValue(MetaType1_13.OptChat, null); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java index 5aab9e90c..55f44f74a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java @@ -139,14 +139,12 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter= 9) { // New piercing diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/metadata/MetadataRewriter1_17To1_16_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/metadata/MetadataRewriter1_17To1_16_4.java index 227ebe684..91e60ed72 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/metadata/MetadataRewriter1_17To1_16_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/metadata/MetadataRewriter1_17To1_16_4.java @@ -37,7 +37,7 @@ public class MetadataRewriter1_17To1_16_4 extends EntityRewriter { filter().handler((event, meta) -> { meta.setMetaType(MetaType1_17.byId(meta.metaType().typeId())); - if (meta.metaType() == MetaType1_17.Pose) { + if (meta.metaType() == MetaType1_17.POSE) { int pose = meta.value(); if (pose > 5) { // Added LONG_JUMP at 6 @@ -45,7 +45,7 @@ public class MetadataRewriter1_17To1_16_4 extends EntityRewriter { } } }); - registerDumMetaTypeHandler(MetaType1_17.Slot, MetaType1_17.BlockID, MetaType1_17.PARTICLE, InventoryPackets::toClient); + registerDumMetaTypeHandler(MetaType1_17.ITEM, MetaType1_17.BLOCK_STATE, MetaType1_17.PARTICLE, InventoryPackets::toClient); // Ticks frozen added with id 7 filter().filterFamily(Entity1_17Types.ENTITY).addIndex(7); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java index 7cee4f61d..57f17c2a5 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetaIndex.java @@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.util.Pair; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.HashMap; import java.util.Optional; @@ -54,11 +55,11 @@ public enum MetaIndex { STAND_RL_POS(ARMOR_STAND, 16, MetaType1_8.Rotation, MetaType1_9.Vector3F), // human, discountined? PLAYER_SKIN_FLAGS(ENTITY_HUMAN, 10, MetaType1_8.Byte, 12, MetaType1_9.Byte), // unsigned on 1.8 - PLAYER_HUMAN_BYTE(ENTITY_HUMAN, 16, MetaType1_8.Byte, MetaType1_9.Discontinued), // unused on 1.8 + PLAYER_HUMAN_BYTE(ENTITY_HUMAN, 16, MetaType1_8.Byte, null), // unused on 1.8 PLAYER_ADDITIONAL_HEARTS(ENTITY_HUMAN, 17, MetaType1_8.Float, 10, MetaType1_9.Float), PLAYER_SCORE(ENTITY_HUMAN, 18, MetaType1_8.Int, 11, MetaType1_9.VarInt), PLAYER_HAND(ENTITY_HUMAN, -1, MetaType1_8.NonExistent, 5, MetaType1_9.Byte), // new in 1.9 - SOMETHING_ANTICHEAT_PLUGINS_FOR_SOME_REASON_USE(ENTITY_HUMAN, 11, MetaType1_8.Byte, MetaType1_9.Discontinued), //For what we know, This doesn't exists. If you think it exists and knows what it does. Please tell us. + SOMETHING_ANTICHEAT_PLUGINS_FOR_SOME_REASON_USE(ENTITY_HUMAN, 11, MetaType1_8.Byte, null), //For what we know, This doesn't exists. If you think it exists and knows what it does. Please tell us. // horse HORSE_INFO(HORSE, 16, MetaType1_8.Int, 12, MetaType1_9.Byte), HORSE_TYPE(HORSE, 19, MetaType1_8.Byte, 13, MetaType1_9.VarInt), @@ -86,7 +87,7 @@ public enum MetaIndex { VILLAGER_PROFESSION(VILLAGER, 16, MetaType1_8.Int, 12, MetaType1_9.VarInt), // enderman ENDERMAN_BLOCKSTATE(ENDERMAN, 16, MetaType1_8.Short, 11, MetaType1_9.BlockID), - ENDERMAN_BLOCKDATA(ENDERMAN, 17, MetaType1_8.Byte, MetaType1_9.Discontinued), //always 0 when sent, never read by the client + ENDERMAN_BLOCKDATA(ENDERMAN, 17, MetaType1_8.Byte, null), //always 0 when sent, never read by the client ENDERMAN_ISSCREAMING(ENDERMAN, 18, MetaType1_8.Byte, 12, MetaType1_9.Boolean), // zombie ZOMBIE_ISCHILD(ZOMBIE, 12, MetaType1_8.Byte, 11, MetaType1_9.Boolean), @@ -117,7 +118,7 @@ public enum MetaIndex { WITHER_TARGET3(WITHER, 19, MetaType1_8.Int, 13, MetaType1_9.VarInt), WITHER_INVULN_TIME(WITHER, 20, MetaType1_8.Int, 14, MetaType1_9.VarInt), WITHER_PROPERTIES(WITHER, 10, MetaType1_8.Byte, MetaType1_9.Byte), - WITHER_UNKNOWN(WITHER, 11, MetaType1_8.Byte, MetaType1_9.Discontinued), + WITHER_UNKNOWN(WITHER, 11, MetaType1_8.Byte, null), // wither skull WITHERSKULL_INVULN(WITHER_SKULL, 10, MetaType1_8.Byte, 5, MetaType1_9.Boolean), // guardian @@ -150,12 +151,12 @@ public enum MetaIndex { ITEMFRAME_ITEM(ITEM_FRAME, 8, MetaType1_8.Slot, 5, MetaType1_9.Slot), ITEMFRAME_ROTATION(ITEM_FRAME, 9, MetaType1_8.Byte, 6, MetaType1_9.VarInt), // ender crystal - ENDERCRYSTAL_HEALTH(ENDER_CRYSTAL, 8, MetaType1_8.Int, MetaType1_9.Discontinued), + ENDERCRYSTAL_HEALTH(ENDER_CRYSTAL, 8, MetaType1_8.Int, null), // Ender dragon boss bar issues - ENDERDRAGON_UNKNOWN(ENDER_DRAGON, 5, MetaType1_8.Byte, MetaType1_9.Discontinued), - ENDERDRAGON_NAME(ENDER_DRAGON, 10, MetaType1_8.String, MetaType1_9.Discontinued), + ENDERDRAGON_UNKNOWN(ENDER_DRAGON, 5, MetaType1_8.Byte, null), + ENDERDRAGON_NAME(ENDER_DRAGON, 10, MetaType1_8.String, null), // Normal Ender dragon - ENDERDRAGON_FLAG(ENDER_DRAGON, 15, MetaType1_8.Byte, MetaType1_9.Discontinued), + ENDERDRAGON_FLAG(ENDER_DRAGON, 15, MetaType1_8.Byte, null), ENDERDRAGON_PHASE(ENDER_DRAGON, 11, MetaType1_8.Byte, MetaType1_9.VarInt); private static final HashMap, MetaIndex> metadataRewrites = new HashMap<>(); @@ -171,7 +172,7 @@ public enum MetaIndex { private final MetaType1_8 oldType; private final int index; - MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, MetaType1_9 newType) { + MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, @Nullable MetaType1_9 newType) { this.clazz = type; this.index = index; this.newIndex = index; @@ -179,7 +180,7 @@ public enum MetaIndex { this.newType = newType; } - MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, int newIndex, MetaType1_9 newType) { + MetaIndex(Entity1_10Types.EntityType type, int index, MetaType1_8 oldType, int newIndex, @Nullable MetaType1_9 newType) { this.clazz = type; this.index = index; this.oldType = oldType; @@ -195,7 +196,7 @@ public enum MetaIndex { return newIndex; } - public MetaType1_9 getNewType() { + public @Nullable MetaType1_9 getNewType() { return newType; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java index 5f73290d2..6a34d1e6c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java @@ -26,7 +26,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_8; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import com.viaversion.viaversion.rewriter.EntityRewriter; @@ -47,13 +46,13 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter { throw new Exception("Could not find valid metadata"); } - if (metaIndex.getNewType() == MetaType1_9.Discontinued) { + if (metaIndex.getNewType() == null) { metadatas.remove(metadata); return; } metadata.setId(metaIndex.getNewIndex()); - metadata.setMetaType(metaIndex.getNewType()); + metadata.setMetaTypeUnsafe(metaIndex.getNewType()); Object value = metadata.getValue(); switch (metaIndex.getNewType()) {