diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/Environment.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/Environment.java index fb098741a..37daddbf3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/Environment.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/Environment.java @@ -1,21 +1,13 @@ package us.myles.ViaVersion.api.minecraft; -import java.util.HashMap; -import java.util.Map; - public enum Environment { + NORMAL(0), NETHER(-1), - END(1); + END(1), + CUSTOM(Integer.MAX_VALUE); private final int id; - private static final Map lookup = new HashMap<>(); - - static { - for (Environment env : values()) { - lookup.put(env.getId(), env); - } - } Environment(int id) { this.id = id; @@ -25,8 +17,28 @@ public enum Environment { return id; } - public static Environment getEnvironmentById(int id) { - return lookup.get(id); + switch (id) { + default: + case -1: + return NETHER; + case 0: + return NORMAL; + case 1: + return END; + } + } + + public static Environment getEnvironmentById(String id) { + switch (id) { + case "minecraft:the_nether": + return NETHER; + case "minecraft:overworld": + return NORMAL; + case "minecraft:the_end": + return END; + default: + return CUSTOM; + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index 0102ca8e8..ce4b0e0bb 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -80,7 +80,7 @@ public class ProtocolVersion { register(v1_15 = new ProtocolVersion(573, "1.15")); register(v1_15_1 = new ProtocolVersion(575, "1.15.1")); register(v1_15_2 = new ProtocolVersion(578, "1.15.2")); - register(v1_16 = new ProtocolVersion(717, "1.16")); + register(v1_16 = new ProtocolVersion(718, "1.16")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java index caae01df2..bc8f4396f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java @@ -20,6 +20,7 @@ import java.util.UUID; public class Protocol1_16To1_15_2 extends Protocol { + public static final UUID ZERO_UUID = new UUID(0, 0); private TagRewriter tagRewriter; public Protocol1_16To1_15_2() { @@ -49,6 +50,16 @@ public class Protocol1_16To1_15_2 extends Protocol { } }); + // Chat Message + registerOutgoing(State.PLAY, 0x0F, 0x0F, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING); + map(Type.BYTE); + handler(wrapper -> wrapper.write(Type.UUID, ZERO_UUID)); // sender uuid + } + }); + // Entity Sound Effect registerOutgoing(State.PLAY, 0x51, 0x51, new PacketRemapper() { @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java index 8ed8eaccf..4855ecae6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java @@ -1,9 +1,14 @@ package us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; +import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.entities.Entity1_16Types; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.packets.State; @@ -15,6 +20,39 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class EntityPackets { + private static final ValueTransformer DIMENSION_TRANSFORMER = new ValueTransformer(Type.INT, Type.STRING) { + @Override + public String transform(PacketWrapper wrapper, Integer input) throws Exception { + switch (input) { + case -1: + return "the_nether"; + case 0: + return "overworld"; + case 1: + return "the_end"; + default: + Via.getPlatform().getLogger().warning("Invalid dimension id: " + input); + return "overworld"; + } + } + }; + private static final CompoundTag DIMENSIONS_TAG = new CompoundTag(""); + + static { + ListTag list = new ListTag("dimension", CompoundTag.class); + list.add(createDimensionEntry("minecraft:overworld")); + list.add(createDimensionEntry("minecraft:the_nether")); + list.add(createDimensionEntry("minecraft:the_end")); + DIMENSIONS_TAG.put(list); + } + + private static CompoundTag createDimensionEntry(String dimension) { + CompoundTag tag = new CompoundTag(""); + tag.put(new StringTag("key", dimension)); + tag.put(new StringTag("element", dimension)); + return tag; + } + public static void register(Protocol protocol) { MetadataRewriter1_16To1_15_2 metadataRewriter = protocol.get(MetadataRewriter1_16To1_15_2.class); @@ -37,12 +75,12 @@ public class EntityPackets { protocol.registerOutgoing(State.PLAY, 0x3B, 0x3B, new PacketRemapper() { @Override public void registerMap() { - map(Type.INT); + map(DIMENSION_TRANSFORMER); map(Type.LONG); map(Type.BYTE); handler(wrapper -> { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - int dimensionId = wrapper.get(Type.INT, 0); + String dimensionId = wrapper.get(Type.STRING, 0); clientWorld.setEnvironment(dimensionId); String levelType = wrapper.read(Type.STRING); @@ -59,13 +97,19 @@ public class EntityPackets { public void registerMap() { map(Type.INT); // Entity ID map(Type.UNSIGNED_BYTE); // Gamemode - map(Type.INT); // Dimension + map(Type.NOTHING, new ValueTransformer(Type.NBT) { // whatever this is + @Override + public CompoundTag transform(PacketWrapper wrapper, Void input) throws Exception { + return DIMENSIONS_TAG; + } + }); + map(DIMENSION_TRANSFORMER); // Dimension map(Type.LONG); // Seed map(Type.UNSIGNED_BYTE); // Max players handler(wrapper -> { ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); - int dimensionId = wrapper.get(Type.INT, 1); - clientChunks.setEnvironment(dimensionId); + String dimension = wrapper.get(Type.STRING, 0); + clientChunks.setEnvironment(dimension); wrapper.user().get(EntityTracker1_16.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16Types.EntityType.PLAYER); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/storage/ClientWorld.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/storage/ClientWorld.java index 5e9be98a2..996891979 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/storage/ClientWorld.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/storage/ClientWorld.java @@ -16,12 +16,10 @@ public class ClientWorld extends StoredObject { } public void setEnvironment(int environmentId) { - this.environment = getEnvFromId(environmentId); + this.environment = Environment.getEnvironmentById(environmentId); } - private Environment getEnvFromId(int id) { - Environment output = Environment.getEnvironmentById(id); - if (output == null) return Environment.NETHER; - return output; + public void setEnvironment(String environmentId) { + this.environment = Environment.getEnvironmentById(environmentId); } } diff --git a/common/src/main/resources/assets/viaversion/data/mapping-1.16.json b/common/src/main/resources/assets/viaversion/data/mapping-1.16.json index 9039059ed..748cb8a9c 100644 --- a/common/src/main/resources/assets/viaversion/data/mapping-1.16.json +++ b/common/src/main/resources/assets/viaversion/data/mapping-1.16.json @@ -19047,6 +19047,7 @@ "entity.donkey.angry", "entity.donkey.chest", "entity.donkey.death", + "entity.donkey.eat", "entity.donkey.hurt", "entity.drowned.ambient", "entity.drowned.ambient_water", @@ -19132,6 +19133,7 @@ "entity.fox.sleep", "entity.fox.sniff", "entity.fox.spit", + "entity.fox.teleport", "block.roots.break", "block.roots.step", "block.roots.place", @@ -19304,8 +19306,10 @@ "entity.mooshroom.suspicious_milk", "entity.mooshroom.shear", "entity.mule.ambient", + "entity.mule.angry", "entity.mule.chest", "entity.mule.death", + "entity.mule.eat", "entity.mule.hurt", "music.creative", "music.credits", @@ -19425,10 +19429,12 @@ "entity.parrot.imitate.evoker", "entity.parrot.imitate.ghast", "entity.parrot.imitate.guardian", + "entity.parrot.imitate.hoglin", "entity.parrot.imitate.husk", "entity.parrot.imitate.illusioner", "entity.parrot.imitate.magma_cube", "entity.parrot.imitate.phantom", + "entity.parrot.imitate.piglin", "entity.parrot.imitate.pillager", "entity.parrot.imitate.ravager", "entity.parrot.imitate.shulker", @@ -19442,6 +19448,7 @@ "entity.parrot.imitate.witch", "entity.parrot.imitate.wither", "entity.parrot.imitate.wither_skeleton", + "entity.parrot.imitate.zoglin", "entity.parrot.imitate.zombie", "entity.parrot.imitate.zombie_villager", "entity.parrot.step",