From 15aa25f0d2bb3dc217fdced2969c4eeb6510eb7f Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 4 Feb 2023 20:16:43 +0100 Subject: [PATCH] Replace some deprecated api usage --- .../rewriters/LegacyBlockItemRewriter.java | 17 +++-- .../packets/EntityPackets1_11.java | 2 +- .../packets/PlayerPackets1_11.java | 2 +- .../packets/ChatItemRewriter.java | 65 ------------------- .../packets/EntityPackets1_12.java | 3 +- .../FlowerPotHandler.java | 4 +- .../packets/BlockItemPackets1_13.java | 27 ++++---- .../packets/PlayerPacket1_13.java | 19 +++--- .../BackwardsBlockEntityProvider.java | 15 +---- .../packets/BlockItemPackets1_14.java | 14 ++-- .../packets/EntityPackets1_14.java | 4 +- .../packets/WorldPackets1_13_1.java | 25 +++---- .../packets/BlockItemPackets1_15.java | 15 +++-- .../packets/BlockItemPackets1_16.java | 14 ++-- .../packets/EntityPackets1_16.java | 2 +- .../Protocol1_16_1To1_16_2.java | 4 +- .../packets/BlockItemPackets1_16_2.java | 14 ++-- .../Protocol1_16_4To1_17.java | 2 +- .../packets/BlockItemPackets1_17.java | 20 ++++-- 19 files changed, 115 insertions(+), 153 deletions(-) delete mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/ChatItemRewriter.java diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java index e887a88c..a2d5be8b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyBlockItemRewriter.java @@ -25,6 +25,8 @@ import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColor import com.viaversion.viabackwards.utils.Block; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType; @@ -182,7 +184,7 @@ public abstract class LegacyBlockItemRewriter> 4]; if (section == null) continue; - int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ()); + int block = section.palette(PaletteType.BLOCKS).idAt(pos.getX(), pos.getY() & 0xF, pos.getZ()); int btype = block >> 4; MappedLegacyBlockItem settings = replacementData.get(btype); @@ -193,19 +195,22 @@ public abstract class LegacyBlockItemRewriter> 4; int meta = block & 0xF; Block b = handleBlock(btype, meta); if (b != null) { - section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF)); + palette.setIdByIndex(j, (b.getId() << 4) | (b.getData() & 0xF)); } // We already know that is has a handler @@ -223,7 +228,7 @@ public abstract class LegacyBlockItemRewriter> 4; int meta = block & 15; diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java index a89e690c..df6b62ef 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java @@ -200,7 +200,7 @@ public class EntityPackets1_11 extends LegacyEntityRewriter. - */ -package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets; - -import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.libs.gson.JsonArray; -import com.viaversion.viaversion.libs.gson.JsonElement; -import com.viaversion.viaversion.libs.gson.JsonObject; -import com.viaversion.viaversion.libs.gson.JsonPrimitive; - -public class ChatItemRewriter { - - public static void toClient(JsonElement element, UserConnection user) { - if (element instanceof JsonObject) { - JsonObject obj = (JsonObject) element; - if (obj.has("hoverEvent")) { - if (obj.get("hoverEvent") instanceof JsonObject) { - JsonObject hoverEvent = (JsonObject) obj.get("hoverEvent"); - if (hoverEvent.has("action") && hoverEvent.has("value")) { - String type = hoverEvent.get("action").getAsString(); - if (type.equals("show_item") || type.equals("show_entity")) { - JsonElement value = hoverEvent.get("value"); - - if (value.isJsonArray()) { - JsonArray newArray = new JsonArray(); - - int index = 0; - for (JsonElement valueElement : value.getAsJsonArray()) { - if (valueElement.isJsonPrimitive() && valueElement.getAsJsonPrimitive().isString()) { - String newValue = index + ":" + valueElement.getAsString(); - newArray.add(new JsonPrimitive(newValue)); - } - } - - hoverEvent.add("value", newArray); - } - } - } - } - } else if (obj.has("extra")) { - toClient(obj.get("extra"), user); - } - } else if (element instanceof JsonArray) { - JsonArray array = (JsonArray) element; - for (JsonElement value : array) { - toClient(value, user); - } - } - } -} diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java index 0a892e65..31be7ff3 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java @@ -36,6 +36,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_12; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ClientboundPackets1_12; +import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import java.util.Optional; public class EntityPackets1_12 extends LegacyEntityRewriter { @@ -154,7 +155,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter item = getOrDefault(blockId); - tag.put("Item", new StringTag(item.getKey())); - tag.put("Data", new IntTag(item.getValue())); + tag.put("Item", new StringTag(item.key())); + tag.put("Data", new IntTag(item.value())); return tag; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 87a330e8..47743c6e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -31,6 +31,8 @@ import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; @@ -45,6 +47,7 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ShortTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; +import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; @@ -189,8 +192,8 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit BackwardsBlockStorage blockStorage = wrapper.user().get(BackwardsBlockStorage.class); blockStorage.getBlocks().entrySet().removeIf(entry -> { Position position = entry.getKey(); - return position.getX() >= chunkMinX && position.getZ() >= chunkMinZ - && position.getX() <= chunkMaxX && position.getZ() <= chunkMaxZ; + return position.x() >= chunkMinX && position.z() >= chunkMinZ + && position.x() <= chunkMaxX && position.z() <= chunkMaxZ; }); } }); @@ -313,7 +316,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit int z = ((NumberTag) tag.get("z")).asInt(); Position position = new Position(x, (short) y, z); - int block = section.getFlatBlock(x & 0xF, y & 0xF, z & 0xF); + int block = section.palette(PaletteType.BLOCKS).idAt(x & 0xF, y & 0xF, z & 0xF); storage.checkAndStore(position, block); provider.transform(wrapper.user(), position, tag); @@ -326,11 +329,12 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit continue; } + DataPalette palette = section.palette(PaletteType.BLOCKS); // Flower pots require a special treatment, they are no longer block entities :( for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { - int block = section.getFlatBlock(x, y, z); + int block = palette.idAt(x, y, z); // Check if the block is a flower if (FlowerPotHandler.isFlowah(block)) { @@ -350,12 +354,9 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit } } - for (int p = 0; p < section.getPaletteSize(); p++) { - int old = section.getPaletteEntry(p); - if (old != 0) { - int oldId = protocol.getMappingData().getNewBlockStateId(old); - section.setPaletteEntry(p, oldId); - } + for (int j = 0; j < palette.size(); j++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j)); + palette.setIdByIndex(j, mappedBlockStateId); } } @@ -1001,19 +1002,19 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit CompoundTag nbt = beProvider.transform(user, position, "minecraft:flower_pot"); // Remove the flowerpot - PacketWrapper blockUpdateRemove = PacketWrapper.create(0x0B, null, user); + PacketWrapper blockUpdateRemove = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_CHANGE, user); blockUpdateRemove.write(Type.POSITION, position); blockUpdateRemove.write(Type.VAR_INT, 0); blockUpdateRemove.scheduleSend(Protocol1_12_2To1_13.class); // Create the flowerpot - PacketWrapper blockCreate = PacketWrapper.create(0x0B, null, user); + PacketWrapper blockCreate = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_CHANGE, user); blockCreate.write(Type.POSITION, position); blockCreate.write(Type.VAR_INT, Protocol1_12_2To1_13.MAPPINGS.getNewBlockStateId(blockState)); blockCreate.scheduleSend(Protocol1_12_2To1_13.class); // Send a block entity update - PacketWrapper wrapper = PacketWrapper.create(0x09, null, user); + PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12_1.BLOCK_ENTITY_DATA, user); wrapper.write(Type.POSITION, position); wrapper.write(Type.UNSIGNED_BYTE, (short) 5); wrapper.write(Type.NBT, nbt); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index e3a51afc..90166744 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -37,6 +37,7 @@ import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPacke import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; +import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; import com.viaversion.viaversion.rewriter.CommandRewriter; @@ -442,14 +443,14 @@ public class PlayerPacket1_13 extends RewriterBase { switch (channel) { case "MC|BSign": case "MC|BEdit": - wrapper.setId(0x0B); + wrapper.setPacketType(ServerboundPackets1_13.EDIT_BOOK); Item book = wrapper.read(Type.ITEM); wrapper.write(Type.FLAT_ITEM, protocol.getItemRewriter().handleItemToServer(book)); boolean signing = channel.equals("MC|BSign"); wrapper.write(Type.BOOLEAN, signing); break; case "MC|ItemName": - wrapper.setId(0x1C); + wrapper.setPacketType(ServerboundPackets1_13.RENAME_ITEM); break; case "MC|AdvCmd": byte type = wrapper.read(Type.BYTE); @@ -457,11 +458,11 @@ public class PlayerPacket1_13 extends RewriterBase { //Information from https://wiki.vg/index.php?title=Plugin_channels&oldid=14089 //The Notchain client only uses this for command block minecarts and uses MC|AutoCmd for blocks, but the Notchian server still accepts it for either. //Maybe older versions used this and we need to implement this? The issues is that we would have to save the command block types - wrapper.setId(0x22); + wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK); wrapper.cancel(); ViaBackwards.getPlatform().getLogger().warning("Client send MC|AdvCmd custom payload to update command block, weird!"); } else if (type == 1) { - wrapper.setId(0x23); + wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK_MINECART); wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Entity Id wrapper.passthrough(Type.STRING); //Command wrapper.passthrough(Type.BOOLEAN); //Track Output @@ -471,7 +472,7 @@ public class PlayerPacket1_13 extends RewriterBase { } break; case "MC|AutoCmd": { - wrapper.setId(0x22); + wrapper.setPacketType(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK); int x = wrapper.read(Type.INT); int y = wrapper.read(Type.INT); @@ -496,7 +497,7 @@ public class PlayerPacket1_13 extends RewriterBase { break; } case "MC|Struct": { - wrapper.setId(0x25); + wrapper.setPacketType(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK); int x = wrapper.read(Type.INT); int y = wrapper.read(Type.INT); int z = wrapper.read(Type.INT); @@ -537,19 +538,19 @@ public class PlayerPacket1_13 extends RewriterBase { break; } case "MC|Beacon": - wrapper.setId(0x20); + wrapper.setPacketType(ServerboundPackets1_13.SET_BEACON_EFFECT); wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Primary Effect wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Secondary Effect break; case "MC|TrSel": - wrapper.setId(0x1F); + wrapper.setPacketType(ServerboundPackets1_13.SELECT_TRADE); wrapper.write(Type.VAR_INT, wrapper.read(Type.INT)); //Slot break; case "MC|PickItem": - wrapper.setId(0x15); + wrapper.setPacketType(ServerboundPackets1_13.PICK_ITEM); break; default: String newChannel = InventoryPackets.getNewPluginChannelId(channel); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java index 6c7e546d..218b8352 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_12_2to1_13/providers/BackwardsBlockEntityProvider.java @@ -18,7 +18,6 @@ package com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.providers; -import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BannerHandler; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BedHandler; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler; @@ -26,7 +25,6 @@ import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_ha import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SkullHandler; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SpawnerHandler; import com.viaversion.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; -import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.platform.providers.Provider; @@ -34,7 +32,6 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; - import java.util.HashMap; import java.util.Map; @@ -76,18 +73,12 @@ public class BackwardsBlockEntityProvider implements Provider { String id = (String) idTag.getValue(); BackwardsBlockEntityHandler handler = handlers.get(id); if (handler == null) { - if (Via.getManager().isDebug()) { - ViaBackwards.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag); - } return tag; } BackwardsBlockStorage storage = user.get(BackwardsBlockStorage.class); Integer blockId = storage.get(position); if (blockId == null) { - if (Via.getManager().isDebug()) { - ViaBackwards.getPlatform().getLogger().warning("Handled BlockEntity does not have a stored block :( " + id + " full tag: " + tag); - } return tag; } @@ -104,9 +95,9 @@ public class BackwardsBlockEntityProvider implements Provider { public CompoundTag transform(UserConnection user, Position position, String id) throws Exception { CompoundTag tag = new CompoundTag(); tag.put("id", new StringTag(id)); - tag.put("x", new IntTag(Math.toIntExact(position.getX()))); - tag.put("y", new IntTag(Math.toIntExact(position.getY()))); - tag.put("z", new IntTag(Math.toIntExact(position.getZ()))); + tag.put("x", new IntTag(Math.toIntExact(position.x()))); + tag.put("y", new IntTag(Math.toIntExact(position.y()))); + tag.put("z", new IntTag(Math.toIntExact(position.z()))); return this.transform(user, position, tag); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java index 54e00881..9b0d39f6 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/BlockItemPackets1_14.java @@ -28,6 +28,8 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLight; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionLightImpl; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.item.Item; @@ -276,7 +278,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit if (entityType == null) return; if (entityType.isOrHasParent(Entity1_14Types.ABSTRACT_HORSE)) { - wrapper.setId(0x3F); + wrapper.setPacketType(ClientboundPackets1_13.ENTITY_METADATA); wrapper.resetReader(); wrapper.passthrough(Type.VAR_INT); wrapper.read(Type.VAR_INT); @@ -452,11 +454,12 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit } } + DataPalette palette = section.palette(PaletteType.BLOCKS); if (Via.getConfig().isNonFullBlockLightFix() && section.getNonAirBlocksCount() != 0 && sectionLight.hasBlockLight()) { for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { - int id = section.getFlatBlock(x, y, z); + int id = palette.idAt(x, y, z); if (Protocol1_14To1_13_2.MAPPINGS.getNonFullBlocks().contains(id)) { sectionLight.getBlockLightNibbleArray().set(x, y, z, 0); } @@ -465,10 +468,9 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit } } - for (int j = 0; j < section.getPaletteSize(); j++) { - int old = section.getPaletteEntry(j); - int newId = protocol.getMappingData().getNewBlockStateId(old); - section.setPaletteEntry(j, newId); + for (int j = 0; j < palette.size(); j++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j)); + palette.setIdByIndex(j, mappedBlockStateId); } } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java index 19726794..181b7e9e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java @@ -62,7 +62,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld)); - for (ChunkSection section : chunk.getSections()) { - if (section != null) { - for (int i = 0; i < section.getPaletteSize(); i++) { - section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i))); - } - } + for (ChunkSection section : chunk.getSections()) { + if (section == null) { + continue; + } + + DataPalette palette = section.palette(PaletteType.BLOCKS); + for (int i = 0; i < palette.size(); i++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i)); + palette.setIdByIndex(i, mappedBlockStateId); } } }); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java index 04412290..6fc0041f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_14_4to1_15/packets/BlockItemPackets1_15.java @@ -20,6 +20,8 @@ package com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.packets; import com.viaversion.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; @@ -99,11 +101,14 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit for (int i = 0; i < chunk.getSections().length; i++) { ChunkSection section = chunk.getSections()[i]; - if (section == null) continue; - for (int j = 0; j < section.getPaletteSize(); j++) { - int old = section.getPaletteEntry(j); - int newId = protocol.getMappingData().getNewBlockStateId(old); - section.setPaletteEntry(j, newId); + if (section == null) { + continue; + } + + DataPalette palette = section.palette(PaletteType.BLOCKS); + for (int j = 0; j < palette.size(); j++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j)); + palette.setIdByIndex(j, mappedBlockStateId); } } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java index 9e330c0e..40637f09 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/BlockItemPackets1_16.java @@ -26,6 +26,8 @@ import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage.Biome import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; @@ -157,10 +159,14 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit for (int i = 0; i < chunk.getSections().length; i++) { ChunkSection section = chunk.getSections()[i]; - if (section == null) continue; - for (int j = 0; j < section.getPaletteSize(); j++) { - int old = section.getPaletteEntry(j); - section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old)); + if (section == null) { + continue; + } + + DataPalette palette = section.palette(PaletteType.BLOCKS); + for (int j = 0; j < palette.size(); j++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(j)); + palette.setIdByIndex(j, mappedBlockStateId); } } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java index 55cfe53c..40888ed4 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/packets/EntityPackets1_16.java @@ -116,7 +116,7 @@ public class EntityPackets1_16 extends EntityRewriter tagList = tags.get(type.getResourceLocation()); + List tagList = tags.get(type.resourceLocation()); IdRewriteFunction rewriter = tagRewriter.getRewriter(type); wrapper.write(Type.VAR_INT, tagList.size()); diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java index ce4d7fc5..49c2af66 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java @@ -28,6 +28,8 @@ import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; @@ -321,7 +323,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter { - int y = wrapper.get(Type.POSITION1_14, 0).getY(); + int y = wrapper.get(Type.POSITION1_14, 0).y(); if (y < 0 || y > 255) { wrapper.cancel(); return; @@ -364,10 +366,14 @@ public final class BlockItemPackets1_17 extends ItemRewriter { - int y = wrapper.passthrough(Type.POSITION1_14).getY(); + int y = wrapper.passthrough(Type.POSITION1_14).y(); if (y < 0 || y > 255) { wrapper.cancel(); } @@ -396,7 +402,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter { - int y = wrapper.passthrough(Type.POSITION1_14).getY(); + int y = wrapper.passthrough(Type.POSITION1_14).y(); if (y < 0 || y > 255) { wrapper.cancel(); }