From 82013d5737d1c3a57524588ac06182d3fb8a8cc1 Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Thu, 25 Oct 2018 20:26:24 +0200 Subject: [PATCH] Keep Chunk as an interface --- .../api/minecraft/chunks/BaseChunk.java | 24 +++++++++++++++ .../api/minecraft/chunks/Chunk.java | 30 +++++++++---------- .../minecraft/chunks/Chunk1_8.java} | 10 +++---- .../api/minecraft/chunks/ChunkSection.java | 3 -- .../types/Chunk1_13Type.java | 3 +- .../types/Chunk1_9_3_4Type.java | 3 +- .../types/Chunk1_9_1_2Type.java | 3 +- .../packets/WorldPackets.java | 4 +-- .../types/Chunk1_9to1_8Type.java | 10 +++---- 9 files changed, 56 insertions(+), 34 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java rename common/src/main/java/us/myles/ViaVersion/{protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java => api/minecraft/chunks/Chunk1_8.java} (65%) 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 new file mode 100644 index 000000000..82dd09429 --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java @@ -0,0 +1,24 @@ +package us.myles.ViaVersion.api.minecraft.chunks; + +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.List; + +@AllArgsConstructor +@Data +public class BaseChunk implements Chunk { + protected int x; + protected int z; + protected boolean groundUp; + protected int bitmask; + protected ChunkSection[] sections; + protected byte[] biomeData; + protected List blockEntities; + + @Override + public boolean isBiomeData() { + return biomeData != null; + } +} 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 67e2c188b..f5b078748 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 @@ -1,23 +1,23 @@ package us.myles.ViaVersion.api.minecraft.chunks; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import lombok.AllArgsConstructor; -import lombok.Data; import java.util.List; -@Data -@AllArgsConstructor -public class Chunk { - protected int x; - protected int z; - protected boolean groundUp; - protected int bitmask; - protected ChunkSection[] sections; - protected byte[] biomeData; - protected List blockEntities; +public interface Chunk { + int getX(); - public boolean isBiomeData() { - return biomeData != null; - } + int getZ(); + + boolean isBiomeData(); + + int getBitmask(); + + ChunkSection[] getSections(); + + byte[] getBiomeData(); + + List getBlockEntities(); + + boolean isGroundUp(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java similarity index 65% rename from common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java rename to common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java index dd775204d..4bfe7f3ed 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk1_8.java @@ -1,18 +1,16 @@ -package us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks; +package us.myles.ViaVersion.api.minecraft.chunks; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import lombok.Getter; -import us.myles.ViaVersion.api.minecraft.chunks.Chunk; -import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import java.util.ArrayList; import java.util.List; -public class Chunk1_9to1_8 extends Chunk { +public class Chunk1_8 extends BaseChunk { @Getter private boolean unloadPacket = false; - public Chunk1_9to1_8(int x, int z, boolean groundUp, int bitmask, ChunkSection[] sections, byte[] biomeData, List blockEntities) { + public Chunk1_8(int x, int z, boolean groundUp, int bitmask, ChunkSection[] sections, byte[] biomeData, List blockEntities) { super(x, z, groundUp, bitmask, sections, biomeData, blockEntities); } @@ -22,7 +20,7 @@ public class Chunk1_9to1_8 extends Chunk { * @param x coord * @param z coord */ - public Chunk1_9to1_8(int x, int z) { + public Chunk1_8(int x, int z) { this(x, z, true, 0, new ChunkSection[16], null, new ArrayList()); this.unloadPacket = true; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java index 2afdbc2cb..133c3f831 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java @@ -14,9 +14,6 @@ public class ChunkSection { * Length of the sky and block light nibble arrays. */ public static final int LIGHT_LENGTH = 16 * 16 * 16 / 2; // size * size * size / 2 (nibble bit count) - /** - * Length of the block data array. - */ private final List palette = Lists.newArrayList(); private final int[] blocks; private NibbleArray blockLight; 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 5c6d1e65b..3d4e40154 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 @@ -4,6 +4,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.Environment; +import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.type.PartialType; @@ -69,7 +70,7 @@ public class Chunk1_13Type extends PartialType { } } - return new Chunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData); + return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData); } @Override 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 87e0e86e0..5f7188ca4 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 @@ -4,6 +4,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.Environment; +import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.type.PartialType; @@ -67,7 +68,7 @@ public class Chunk1_9_3_4Type extends PartialType { } } - return new Chunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData); + return new BaseChunk(chunkX, chunkZ, groundUp, 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 77d483144..63ff5695d 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 @@ -4,6 +4,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.minecraft.Environment; +import us.myles.ViaVersion.api.minecraft.chunks.BaseChunk; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.type.PartialType; @@ -65,7 +66,7 @@ public class Chunk1_9_1_2Type extends PartialType { input.readBytes(biomeData); } - return new Chunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, new ArrayList()); + return new BaseChunk(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, new ArrayList()); } @Override diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java index f6605c692..f6fb17809 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -16,7 +16,7 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.Chunk1_9to1_8; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect; @@ -121,7 +121,7 @@ public class WorldPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); - Chunk1_9to1_8 chunk = (Chunk1_9to1_8) wrapper.passthrough(new Chunk1_9to1_8Type(clientChunks)); + Chunk1_8 chunk = (Chunk1_8) wrapper.passthrough(new Chunk1_9to1_8Type(clientChunks)); if (chunk.isUnloadPacket()) { wrapper.setId(0x1D); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java index 40115b9a4..877a5aa5c 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/Chunk1_9to1_8Type.java @@ -12,7 +12,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_8; import us.myles.ViaVersion.api.type.types.version.Types1_9; import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; -import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.Chunk1_9to1_8; +import us.myles.ViaVersion.api.minecraft.chunks.Chunk1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks; import java.util.ArrayList; @@ -77,7 +77,7 @@ public class Chunk1_9to1_8Type extends PartialType { if (sectionCount == 0 && groundUp && !isBulkPacket && param.getLoadedChunks().contains(chunkHash)) { // This is a chunks unload packet param.getLoadedChunks().remove(chunkHash); - return new Chunk1_9to1_8(chunkX, chunkZ); + return new Chunk1_8(chunkX, chunkZ); } int startIndex = input.readerIndex(); @@ -123,14 +123,14 @@ public class Chunk1_9to1_8Type extends PartialType { } // Return chunks - return new Chunk1_9to1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList()); + return new Chunk1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList()); } @Override public void write(ByteBuf output, ClientChunks param, Chunk input) throws Exception { - if (!(input instanceof Chunk1_9to1_8)) throw new Exception("Incompatible chunk, " + input.getClass()); + if (!(input instanceof Chunk1_8)) throw new Exception("Incompatible chunk, " + input.getClass()); - Chunk1_9to1_8 chunk = (Chunk1_9to1_8) input; + Chunk1_8 chunk = (Chunk1_8) input; // Write primary info output.writeInt(chunk.getX()); output.writeInt(chunk.getZ());