From 9785878d876151853f5da0624da28875deb1989c Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 16 Jun 2020 18:38:16 +0200 Subject: [PATCH] 1.16 pre7 --- .../api/minecraft/chunks/BaseChunk.java | 18 ++++++++++++++--- .../api/minecraft/chunks/Chunk.java | 4 ++++ .../api/minecraft/chunks/Chunk1_8.java | 2 +- .../api/protocol/ProtocolVersion.java | 2 +- .../api/rewriters/ItemRewriter.java | 20 +++++++++++++++++++ .../types/Chunk1_13Type.java | 2 +- .../types/Chunk1_14Type.java | 2 +- .../types/Chunk1_15Type.java | 2 +- .../packets/InventoryPackets.java | 14 ++++++++++++- .../packets/WorldPackets.java | 3 +++ .../types/Chunk1_16Type.java | 4 +++- .../types/Chunk1_9_3_4Type.java | 2 +- .../types/Chunk1_9_1_2Type.java | 2 +- 13 files changed, 65 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java index 51a318087..f6e482e16 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java @@ -8,16 +8,18 @@ public class BaseChunk implements Chunk { protected final int x; protected final int z; protected final boolean fullChunk; + protected boolean ignoreOldLightData; protected final int bitmask; protected final ChunkSection[] sections; protected int[] biomeData; protected CompoundTag heightMap; protected final List blockEntities; - public BaseChunk(int x, int z, boolean fullChunk, int bitmask, ChunkSection[] sections, int[] biomeData, CompoundTag heightMap, List blockEntities) { + public BaseChunk(int x, int z, boolean fullChunk, boolean ignoreOldLightData, int bitmask, ChunkSection[] sections, int[] biomeData, CompoundTag heightMap, List blockEntities) { this.x = x; this.z = z; this.fullChunk = fullChunk; + this.ignoreOldLightData = ignoreOldLightData; this.bitmask = bitmask; this.sections = sections; this.biomeData = biomeData; @@ -25,8 +27,8 @@ public class BaseChunk implements Chunk { this.blockEntities = blockEntities; } - public BaseChunk(int x, int z, boolean fullChunk, int bitmask, ChunkSection[] sections, int[] biomeData, List blockEntities) { - this(x, z, fullChunk, bitmask, sections, biomeData, null, blockEntities); + public BaseChunk(int x, int z, boolean fullChunk, boolean ignoreOldLightData, int bitmask, ChunkSection[] sections, int[] biomeData, List blockEntities) { + this(x, z, fullChunk, ignoreOldLightData, bitmask, sections, biomeData, null, blockEntities); } @Override @@ -49,6 +51,16 @@ public class BaseChunk implements Chunk { return fullChunk; } + @Override + public boolean isIgnoreOldLightData() { + return ignoreOldLightData; + } + + @Override + public void setIgnoreOldLightData(boolean ignoreOldLightData) { + this.ignoreOldLightData = ignoreOldLightData; + } + @Override public int getBitmask() { return bitmask; diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java index 9e7d88dbc..018073de8 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java @@ -19,6 +19,10 @@ public interface Chunk { return isFullChunk(); } + boolean isIgnoreOldLightData(); + + void setIgnoreOldLightData(boolean ignoreOldLightData); + int getBitmask(); ChunkSection[] getSections(); diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java index bdb8d5cad..990cc40af 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java @@ -9,7 +9,7 @@ public class Chunk1_8 extends BaseChunk { private boolean unloadPacket; public Chunk1_8(int x, int z, boolean groundUp, int bitmask, ChunkSection[] sections, int[] biomeData, List blockEntities) { - super(x, z, groundUp, bitmask, sections, biomeData, blockEntities); + super(x, z, groundUp, false, bitmask, sections, biomeData, blockEntities); } /** 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 5128ba738..3cb627c92 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(730, "1.16")); + register(v1_16 = new ProtocolVersion(732, "1.16")); register(unknown = new ProtocolVersion(-1, "UNKNOWN")); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java index 4495feca8..b91efa56e 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java @@ -45,6 +45,7 @@ public class ItemRewriter { }); } + // Sub 1.16 public void registerEntityEquipment(ClientboundPacketType packetType, Type type) { protocol.registerOutgoing(packetType, new PacketRemapper() { @Override @@ -58,6 +59,25 @@ public class ItemRewriter { }); } + // 1.16+ + public void registerEntityEquipmentArray(ClientboundPacketType packetType, Type type) { + protocol.registerOutgoing(packetType, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + + handler(wrapper -> { + byte slot; + do { + slot = wrapper.read(Type.BYTE); + // & 0x7F into an extra variable if slot is needed + toClient.rewrite(wrapper.passthrough(type)); + } while ((slot & 0xFFFFFF80) != 0); + }); + } + }); + } + public void registerCreativeInvAction(ServerboundPacketType packetType, Type type) { protocol.registerIncoming(packetType, new PacketRemapper() { @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java index 7de8e508a..7d759be11 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/types/Chunk1_13Type.java @@ -66,7 +66,7 @@ public class Chunk1_13Type extends PartialType { } } - return new BaseChunk(chunkX, chunkZ, fullChunk, primaryBitmask, sections, biomeData, nbtData); + return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/types/Chunk1_14Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/types/Chunk1_14Type.java index 43f2d7b74..3d498725c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/types/Chunk1_14Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/types/Chunk1_14Type.java @@ -61,7 +61,7 @@ public class Chunk1_14Type extends PartialType { } } - return new BaseChunk(chunkX, chunkZ, fullChunk, primaryBitmask, sections, biomeData, heightMap, nbtData); + return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java index a947a585b..26233cd3c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/types/Chunk1_15Type.java @@ -62,7 +62,7 @@ public class Chunk1_15Type extends PartialType { } } - return new BaseChunk(chunkX, chunkZ, fullChunk, primaryBitmask, sections, biomeData, heightMap, nbtData); + return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java index 02833f7c3..e27451ec3 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java @@ -95,7 +95,19 @@ public class InventoryPackets { }); itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM); - itemRewriter.registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM); + + protocol.registerOutgoing(ClientboundPackets1_15.ENTITY_EQUIPMENT, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity ID + + handler(wrapper -> { + int slot = wrapper.read(Type.VAR_INT); + wrapper.write(Type.BYTE, (byte) slot); + InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); + }); + } + }); protocol.registerOutgoing(ClientboundPackets1_15.DECLARE_RECIPES, new PacketRemapper() { @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java index 8b8ca2aa8..8df3e45d2 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java @@ -47,6 +47,9 @@ public class WorldPackets { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk chunk = wrapper.read(new Chunk1_15Type(clientWorld)); wrapper.write(new Chunk1_16Type(clientWorld), chunk); + + chunk.setIgnoreOldLightData(chunk.isFullChunk()); + for (int s = 0; s < 16; s++) { ChunkSection section = chunk.getSections()[s]; if (section == null) continue; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/types/Chunk1_16Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/types/Chunk1_16Type.java index 123cd96cb..0d3fc28df 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/types/Chunk1_16Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16to1_15_2/types/Chunk1_16Type.java @@ -29,6 +29,7 @@ public class Chunk1_16Type extends PartialType { int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); + boolean ignoreOldLightData = input.readBoolean(); int primaryBitmask = Type.VAR_INT.read(input); CompoundTag heightMap = Type.NBT.read(input); @@ -62,7 +63,7 @@ public class Chunk1_16Type extends PartialType { } } - return new BaseChunk(chunkX, chunkZ, fullChunk, primaryBitmask, sections, biomeData, heightMap, nbtData); + return new BaseChunk(chunkX, chunkZ, fullChunk, ignoreOldLightData, primaryBitmask, sections, biomeData, heightMap, nbtData); } @Override @@ -71,6 +72,7 @@ public class Chunk1_16Type extends PartialType { output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); + output.writeBoolean(chunk.isIgnoreOldLightData()); Type.VAR_INT.write(output, chunk.getBitmask()); Type.NBT.write(output, chunk.getHeightMap()); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java index 3669c213e..243d313b5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/types/Chunk1_9_3_4Type.java @@ -62,7 +62,7 @@ public class Chunk1_9_3_4Type extends PartialType { } } - return new BaseChunk(chunkX, chunkZ, fullChunk, primaryBitmask, sections, biomeData, nbtData); + return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java index c0303836c..02f226ef8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/types/Chunk1_9_1_2Type.java @@ -66,7 +66,7 @@ public class Chunk1_9_1_2Type extends PartialType { } } - return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, new ArrayList()); + return new BaseChunk(chunkX, chunkZ, groundUp, false, primaryBitmask, sections, biomeData, new ArrayList()); } @Override