From 7296017ab8e55c585f66482accc426b7c444460c Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Tue, 20 Nov 2018 15:32:49 +0100 Subject: [PATCH] ViaVersion 2.0.0 compatibility --- .../api/rewriters/BlockItemRewriter.java | 65 ++++++++++++------- .../packets/BlockItemPackets1_11.java | 4 +- .../packets/BlockItemPackets1_12.java | 4 +- .../packets/BlockItemPackets1_10.java | 4 +- pom.xml | 2 +- 5 files changed, 50 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java index c8ebd273..3ad77ff2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java @@ -138,10 +138,18 @@ public abstract class BlockItemRewriter extends Rew if (!(tag.contains("x") && tag.contains("y") && tag.contains("z"))) continue; Pos pos = new Pos( - (int) tag.get("x").getValue() % 16, + (int) tag.get("x").getValue() & 0xF, (int) tag.get("y").getValue(), - (int) tag.get("z").getValue() % 16); + (int) tag.get("z").getValue() & 0xF); tags.put(pos, tag); + + // Handle given Block Entities + ChunkSection section = chunk.getSections()[pos.getY() >> 4]; + if (section == null) continue; + int block = section.getFlatBlock(pos.getX(), pos.getY() & 0xF, pos.getZ()); + int btype = block >> 4; + if (!hasBlockEntityHandler(btype)) continue; + replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag); } for (int i = 0; i < chunk.getSections().length; i++) { @@ -149,32 +157,45 @@ public abstract class BlockItemRewriter extends Rew if (section == null) continue; + boolean hasBlockEntityHandler = false; + + // Map blocks + for (int j = 0; j < section.getPaletteSize(); j++) { + int block = section.getPaletteEntry(j); + int btype = block >> 4; + int meta = block & 0xF; + + if (containsBlock(btype)) { + Block b = handleBlock(btype, meta); + section.setPaletteEntry(j, (b.getId() << 4) | (b.getData() & 0xF)); + } + + hasBlockEntityHandler = hasBlockEntityHandler || hasBlockEntityHandler(btype); + } + + if (!hasBlockEntityHandler) continue; + + // We need to handle a Block Entity :( for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { - int block = section.getBlock(x, y, z); + int block = section.getFlatBlock(x, y, z); int btype = block >> 4; int meta = block & 15; - if (containsBlock(btype)) { - Block b = handleBlock(btype, meta); // Type / data - section.setBlock(x, y, z, b.getId(), b.getData()); - } - // Entity Tags - if (hasBlockEntityHandler(btype)) { - Pos pos = new Pos(x, (y + (i << 4)), z); - CompoundTag tag = null; - if (tags.containsKey(pos)) { - tag = tags.get(pos); - } else { - tag = new CompoundTag(""); - tag.put(new IntTag("x", x + (chunk.getX() << 4))); - tag.put(new IntTag("y", y + (i << 4))); - tag.put(new IntTag("z", z + (chunk.getZ() << 4))); - chunk.getBlockEntities().add(tag); - } - replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag); - } + if (!hasBlockEntityHandler(btype)) continue; + + Pos pos = new Pos(x, (y + (i << 4)), z); + + // Already handled above + if (tags.containsKey(pos)) continue; + + CompoundTag tag = new CompoundTag(""); + tag.put(new IntTag("x", x + (chunk.getX() << 4))); + tag.put(new IntTag("y", y + (i << 4))); + tag.put(new IntTag("z", z + (chunk.getZ() << 4))); + replacementData.get(btype).getBlockEntityHandler().handleOrNewCompoundTag(block, tag); + chunk.getBlockEntities().add(tag); } } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 80509d0a..10519452 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -22,13 +22,13 @@ import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -226,7 +226,7 @@ public class BlockItemPackets1_11 extends BlockItemRewriter ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); // Use the 1.10 Chunk type since nothing changed. - Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type); + Chunk chunk = wrapper.passthrough(type); handleChunk(chunk); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java index bd60e6fd..fc87650f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java @@ -15,13 +15,13 @@ import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; @@ -171,7 +171,7 @@ public class BlockItemPackets1_12 extends BlockItemRewriter ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld); - Chunk1_9_3_4 chunk = (Chunk1_9_3_4) wrapper.passthrough(type); + Chunk chunk = wrapper.passthrough(type); handleChunk(chunk); } diff --git a/pom.xml b/pom.xml index 37264eec..9a000266 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ us.myles viaversion - 1.4.1 + 2.0.0-SNAPSHOT provided