diff --git a/src/main/java/net/raphimc/vialegacy/protocols/beta/protocol1_0_0_1tob1_8_0_1/types/Typesb1_8_0_1.java b/src/main/java/net/raphimc/vialegacy/protocols/beta/protocol1_0_0_1tob1_8_0_1/types/Typesb1_8_0_1.java index 295cb06..42071a9 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/beta/protocol1_0_0_1tob1_8_0_1/types/Typesb1_8_0_1.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/beta/protocol1_0_0_1tob1_8_0_1/types/Typesb1_8_0_1.java @@ -19,11 +19,9 @@ package net.raphimc.vialegacy.protocols.beta.protocol1_0_0_1tob1_8_0_1.types; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.type.Type; -import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ItemArrayType; public class Typesb1_8_0_1 { public static final Type CREATIVE_ITEM = new NbtLessItemType(); - public static final Type CREATIVE_ITEM_ARRAY = new ItemArrayType<>(CREATIVE_ITEM); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_28_30cpe/Protocolc0_30toc0_30cpe.java b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_28_30cpe/Protocolc0_30toc0_30cpe.java index 6a6ef01..759060f 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_28_30cpe/Protocolc0_30toc0_30cpe.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/classic/protocolc0_28_30toc0_28_30cpe/Protocolc0_30toc0_30cpe.java @@ -26,7 +26,7 @@ import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.CustomByteType; +import com.viaversion.viaversion.api.type.types.FixedByteArrayType; import net.raphimc.vialegacy.ViaLegacy; import net.raphimc.vialegacy.api.data.BlockList1_6; import net.raphimc.vialegacy.api.model.ChunkCoord; @@ -220,8 +220,8 @@ public class Protocolc0_30toc0_30cpe extends StatelessProtocol> records = new HashMap<>(); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/ChunkType1_1.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/ChunkType1_1.java index 9c35631..58a9d6d 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/ChunkType1_1.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_2_1_3to1_1/types/ChunkType1_1.java @@ -20,8 +20,7 @@ package net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.*; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.CustomByteType; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; +import com.viaversion.viaversion.api.type.types.FixedByteArrayType; import io.netty.buffer.ByteBuf; import net.raphimc.vialegacy.api.model.IdAndData; import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.chunks.NibbleArray1_1; @@ -38,11 +37,6 @@ public class ChunkType1_1 extends Type { super(Chunk.class); } - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } - @Override public Chunk read(ByteBuf byteBuf) throws Exception { final int xPosition = byteBuf.readInt(); @@ -52,7 +46,7 @@ public class ChunkType1_1 extends Type { final int ySize = byteBuf.readUnsignedByte() + 1; final int zSize = byteBuf.readUnsignedByte() + 1; final int chunkSize = byteBuf.readInt(); - final byte[] compressedData = new CustomByteType(chunkSize).read(byteBuf); + final byte[] compressedData = new FixedByteArrayType(chunkSize).read(byteBuf); final byte[] uncompressedData = new byte[(xSize * ySize * zSize * 5) / 2]; final Inflater inflater = new Inflater(); inflater.setInput(compressedData); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java index 6f334b3..433646b 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/Protocol1_3_1_2to1_2_4_5.java @@ -459,7 +459,7 @@ public class Protocol1_3_1_2to1_2_4_5 extends StatelessProtocol()); - wrapper.write(new ChunkType1_7_6(wrapper.user().get(ClientWorld.class)), chunk); + wrapper.write(Types1_7_6.getChunk(wrapper.user().get(ClientWorld.class).getEnvironment()), chunk); } else { wrapper.cancel(); } @@ -470,7 +470,7 @@ public class Protocol1_3_1_2to1_2_4_5 extends StatelessProtocol { - final ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + final Environment environment = wrapper.user().get(ClientWorld.class).getEnvironment(); Chunk chunk = wrapper.read(Types1_2_4.CHUNK); wrapper.user().get(ChestStateTracker.class).unload(chunk.getX(), chunk.getZ()); @@ -481,7 +481,7 @@ public class Protocol1_3_1_2to1_2_4_5 extends StatelessProtocol { - private final boolean compressed; - - public ItemType(boolean compressed) { + public ItemType() { super(Item.class); - this.compressed = compressed; } public Item read(ByteBuf buffer) throws Exception { @@ -43,7 +40,7 @@ public class ItemType extends Type { item.setAmount(buffer.readByte()); item.setData(buffer.readShort()); if (NbtItemList.hasNbt(id)) { - item.setTag((this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).read(buffer)); + item.setTag(Types1_7_6.COMPRESSED_NBT.read(buffer)); } return item; } @@ -57,7 +54,7 @@ public class ItemType extends Type { buffer.writeByte(item.amount()); buffer.writeShort(item.data()); if (NbtItemList.hasNbt(item.identifier())) { - (this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).write(buffer, item.tag()); + Types1_7_6.COMPRESSED_NBT.write(buffer, item.tag()); } } } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java index 957fca2..1745cef 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java @@ -24,10 +24,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ItemA public class Types1_2_4 { - public static final Type ITEM = new ItemType(false); - public static final Type COMPRESSED_NBT_ITEM = new ItemType(true); - - public static final Type ITEM_ARRAY = new ItemArrayType<>(ITEM); + public static final Type COMPRESSED_NBT_ITEM = new ItemType(); public static final Type COMPRESSED_NBT_ITEM_ARRAY = new ItemArrayType<>(COMPRESSED_NBT_ITEM); public static final Type CHUNK = new ChunkType1_2_4(); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/types/Types1_3_1.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/types/Types1_3_1.java index 78bc4b8..b327ba2 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/types/Types1_3_1.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_2to1_3_1_2/types/Types1_3_1.java @@ -28,7 +28,6 @@ import java.util.List; public class Types1_3_1 { public static final Type NBTLESS_ITEM = new NbtLessItemType(); - public static final Type NBTLESS_ITEM_ARRAY = new ItemArrayType<>(NBTLESS_ITEM); public static final Type METADATA = new MetadataType(); public static final Type> METADATA_LIST = new MetaListType(METADATA); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/Protocol1_4_6_7to1_4_4_5.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/Protocol1_4_6_7to1_4_4_5.java index 2c7a121..615cdcf 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/Protocol1_4_6_7to1_4_4_5.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/Protocol1_4_6_7to1_4_4_5.java @@ -20,6 +20,7 @@ package net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5; import com.google.common.collect.Lists; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.ClientWorld; +import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; @@ -30,13 +31,14 @@ import net.raphimc.vialegacy.api.protocol.StatelessProtocol; import net.raphimc.vialegacy.api.remapper.LegacyItemRewriter; import net.raphimc.vialegacy.api.splitter.PreNettySplitter; import net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5.rewriter.ItemRewriter; -import net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5.types.ChunkBulkType1_4_4; +import net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5.types.BulkChunkType1_4_4; +import net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5.types.Types1_4_4; import net.raphimc.vialegacy.protocols.release.protocol1_5_0_1to1_4_6_7.ClientboundPackets1_4_6; import net.raphimc.vialegacy.protocols.release.protocol1_6_1to1_5_2.ServerboundPackets1_5_2; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.MetaType1_6_4; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Types1_6_4; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.metadata.MetaIndex1_8to1_7_6; -import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkBulkType1_7_6; +import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.BulkChunkType1_7_6; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6; public class Protocol1_4_6_7to1_4_4_5 extends StatelessProtocol { @@ -127,10 +129,7 @@ public class Protocol1_4_6_7to1_4_4_5 extends StatelessProtocol { - final ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - wrapper.write(new ChunkBulkType1_7_6(clientWorld), wrapper.read(new ChunkBulkType1_4_4(clientWorld))); - }); + map(Types1_7_6.CHUNK_BULK, Types1_4_4.CHUNK_BULK); } }); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/ChunkBulkType1_4_4.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/BulkChunkType1_4_4.java similarity index 70% rename from src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/ChunkBulkType1_4_4.java rename to src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/BulkChunkType1_4_4.java index ea3f068..d5f6d16 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/ChunkBulkType1_4_4.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/BulkChunkType1_4_4.java @@ -17,23 +17,18 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5.types; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import io.netty.buffer.ByteBuf; -import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkBulkType1_7_6; +import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.BulkChunkType1_7_6; -public class ChunkBulkType1_4_4 extends ChunkBulkType1_7_6 { - - public ChunkBulkType1_4_4(ClientWorld clientWorld) { - super(clientWorld); - } +public class BulkChunkType1_4_4 extends BulkChunkType1_7_6 { @Override - protected boolean readHasSkyLight(ByteBuf byteBuf, ClientWorld clientWorld) { + protected boolean readHasSkyLight(ByteBuf byteBuf) { return true; } @Override - protected void writeHasSkyLight(ByteBuf byteBuf, ClientWorld clientWorld, boolean hasSkyLight) { + protected void writeHasSkyLight(ByteBuf byteBuf, boolean hasSkyLight) { } } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/Types1_4_4.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/Types1_4_4.java new file mode 100644 index 0000000..a34d49e --- /dev/null +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/Types1_4_4.java @@ -0,0 +1,24 @@ +/* + * This file is part of ViaLegacy - https://github.com/RaphiMC/ViaLegacy + * Copyright (C) 2023 RK_01/RaphiMC and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.raphimc.vialegacy.protocols.release.protocol1_4_6_7to1_4_4_5.types; + +public class Types1_4_4 { + + public static final BulkChunkType1_4_4 CHUNK_BULK = new BulkChunkType1_4_4(); + +} diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java index 785137e..19897df 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java @@ -67,7 +67,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.Protocol1_8 import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameProfile; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkType1_7_6; -import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkBulkType1_7_6; +import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.BulkChunkType1_7_6; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.MetaType1_7_6; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6; @@ -421,7 +421,7 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol { - final Chunk chunk = wrapper.passthrough(new ChunkType1_7_6(wrapper.user().get(ClientWorld.class))); + final Chunk chunk = wrapper.passthrough(Types1_7_6.getChunk(wrapper.user().get(ClientWorld.class).getEnvironment())); wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk); }); } @@ -486,7 +486,7 @@ public class Protocol1_7_2_5to1_6_4 extends StatelessTransitionProtocol { - final Chunk[] chunks = wrapper.passthrough(new ChunkBulkType1_7_6(wrapper.user().get(ClientWorld.class))); + final Chunk[] chunks = wrapper.passthrough(Types1_7_6.CHUNK_BULK); for (Chunk chunk : chunks) { wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java index 8e17e6e..31d25c8 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java @@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.connection.ProtocolInfo; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.ClientWorld; +import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_10; @@ -63,7 +64,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.Ch import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.ItemRewriter; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.TranslationRewriter; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.storage.*; -import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkBulkType1_7_6; +import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.BulkChunkType1_7_6; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkType1_7_6; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Types1_7_6; @@ -633,9 +634,11 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol { - final Chunk chunk = wrapper.read(new ChunkType1_7_6(wrapper.user().get(ClientWorld.class))); + final Environment environment = wrapper.user().get(ClientWorld.class).getEnvironment(); + + final Chunk chunk = wrapper.read(Types1_7_6.getChunk(environment)); wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk); - wrapper.write(new ChunkType1_8(wrapper.user().get(ClientWorld.class)), chunk); + wrapper.write(ChunkType1_8.forEnvironment(environment), chunk); }); } }); @@ -696,11 +699,11 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol { - final Chunk[] chunks = wrapper.read(new ChunkBulkType1_7_6(wrapper.user().get(ClientWorld.class))); + final Chunk[] chunks = wrapper.read(Types1_7_6.CHUNK_BULK); for (Chunk chunk : chunks) { wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk); } - wrapper.write(new BulkChunkType1_8(wrapper.user().get(ClientWorld.class)), chunks); + wrapper.write(BulkChunkType1_8.TYPE, chunks); }); } }); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkBulkType1_7_6.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/BulkChunkType1_7_6.java similarity index 81% rename from src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkBulkType1_7_6.java rename to src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/BulkChunkType1_7_6.java index d7af4fd..683630c 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkBulkType1_7_6.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/BulkChunkType1_7_6.java @@ -17,12 +17,9 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; -import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.CustomByteType; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkBulkType; +import com.viaversion.viaversion.api.type.types.FixedByteArrayType; import com.viaversion.viaversion.util.Pair; import io.netty.buffer.ByteBuf; @@ -32,25 +29,19 @@ import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; -public class ChunkBulkType1_7_6 extends PartialType { +public class BulkChunkType1_7_6 extends Type { - public ChunkBulkType1_7_6(final ClientWorld clientWorld) { - super(clientWorld, Chunk[].class); - } - - @Override - public Class getBaseClass() { - return BaseChunkBulkType.class; + public BulkChunkType1_7_6() { + super(Chunk[].class); } /** * This method is here to allow overriding the code for 1.4.5 -{@literal >} 1.4.7 * - * @param byteBuf The buffer - * @param clientWorld The ClientWorld + * @param byteBuf The buffer * @return Read skylight array or not */ - protected boolean readHasSkyLight(final ByteBuf byteBuf, final ClientWorld clientWorld) { + protected boolean readHasSkyLight(final ByteBuf byteBuf) { return byteBuf.readBoolean(); } @@ -58,19 +49,18 @@ public class ChunkBulkType1_7_6 extends PartialType { * This method is here to allow overriding the code for 1.4.5 -{@literal >} 1.4.7 * * @param byteBuf The buffer - * @param clientWorld The ClientWorld * @param hasSkyLight Has skylight */ - protected void writeHasSkyLight(final ByteBuf byteBuf, final ClientWorld clientWorld, final boolean hasSkyLight) { + protected void writeHasSkyLight(final ByteBuf byteBuf, final boolean hasSkyLight) { byteBuf.writeBoolean(hasSkyLight); } @Override - public Chunk[] read(ByteBuf byteBuf, ClientWorld clientWorld) throws Exception { + public Chunk[] read(ByteBuf byteBuf) throws Exception { final short chunkCount = byteBuf.readShort(); final int compressedSize = byteBuf.readInt(); - final boolean hasSkyLight = this.readHasSkyLight(byteBuf, clientWorld); - final byte[] data = new CustomByteType(compressedSize).read(byteBuf); + final boolean hasSkyLight = this.readHasSkyLight(byteBuf); + final byte[] data = new FixedByteArrayType(compressedSize).read(byteBuf); final int[] chunkX = new int[chunkCount]; final int[] chunkZ = new int[chunkCount]; final short[] primaryBitMask = new short[chunkCount]; @@ -106,7 +96,7 @@ public class ChunkBulkType1_7_6 extends PartialType { } @Override - public void write(ByteBuf byteBuf, ClientWorld clientWorld, Chunk[] chunks) throws Exception { + public void write(ByteBuf byteBuf, Chunk[] chunks) throws Exception { final int chunkCount = chunks.length; final ByteArrayOutputStream output = new ByteArrayOutputStream(); final int[] chunkX = new int[chunkCount]; @@ -139,7 +129,7 @@ public class ChunkBulkType1_7_6 extends PartialType { byteBuf.writeShort(chunkCount); byteBuf.writeInt(compressedSize); - this.writeHasSkyLight(byteBuf, clientWorld, true); + this.writeHasSkyLight(byteBuf, true); byteBuf.writeBytes(compressedData, 0, compressedSize); for (int i = 0; i < chunkCount; i++) { diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkType1_7_6.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkType1_7_6.java index 3c51410..3521141 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkType1_7_6.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ChunkType1_7_6.java @@ -17,13 +17,9 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types; -import com.viaversion.viaversion.api.minecraft.ClientWorld; -import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.*; -import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.CustomByteType; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; +import com.viaversion.viaversion.api.type.types.FixedByteArrayType; import com.viaversion.viaversion.util.Pair; import io.netty.buffer.ByteBuf; import net.raphimc.vialegacy.api.model.IdAndData; @@ -36,48 +32,44 @@ import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; -public class ChunkType1_7_6 extends PartialType { +public class ChunkType1_7_6 extends Type { - public ChunkType1_7_6(final ClientWorld clientWorld) { - super(clientWorld, Chunk.class); - } + private final boolean hasSkyLight; - @Override - public Class getBaseClass() { - return BaseChunkType.class; + public ChunkType1_7_6(boolean hasSkyLight) { + super(Chunk.class); + this.hasSkyLight = hasSkyLight; } /** * This method is here to allow overriding the code for 1.2.5 -{@literal >} 1.3.2 because it introduced an unused int * * @param byteBuf The buffer - * @param clientWorld The ClientWorld */ - protected void readUnusedInt(final ByteBuf byteBuf, final ClientWorld clientWorld) { + protected void readUnusedInt(final ByteBuf byteBuf) { } /** * This method is here to allow overriding the code for 1.2.5 -{@literal >} 1.3.2 because it introduced an unused int * * @param byteBuf The buffer - * @param clientWorld The ClientWorld * @param chunk The Chunk */ - protected void writeUnusedInt(final ByteBuf byteBuf, final ClientWorld clientWorld, final Chunk chunk) { + protected void writeUnusedInt(final ByteBuf byteBuf, final Chunk chunk) { } @Override - public Chunk read(ByteBuf byteBuf, ClientWorld clientWorld) throws Exception { + public Chunk read(ByteBuf byteBuf) throws Exception { final int chunkX = byteBuf.readInt(); final int chunkZ = byteBuf.readInt(); final boolean fullChunk = byteBuf.readBoolean(); final short primaryBitMask = byteBuf.readShort(); final short additionalBitMask = byteBuf.readShort(); final int compressedSize = byteBuf.readInt(); - this.readUnusedInt(byteBuf, clientWorld); - final byte[] data = new CustomByteType(compressedSize).read(byteBuf); + this.readUnusedInt(byteBuf); + final byte[] data = new FixedByteArrayType(compressedSize).read(byteBuf); - final byte[] uncompressedData = new byte[getSize(primaryBitMask, additionalBitMask, fullChunk, clientWorld.getEnvironment() == Environment.NORMAL)]; + final byte[] uncompressedData = new byte[getSize(primaryBitMask, additionalBitMask, fullChunk, this.hasSkyLight)]; final Inflater inflater = new Inflater(); try { inflater.setInput(data, 0, compressedSize); @@ -93,11 +85,11 @@ public class ChunkType1_7_6 extends PartialType { return new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>()); } - return deserialize(chunkX, chunkZ, fullChunk, clientWorld.getEnvironment() == Environment.NORMAL, primaryBitMask, additionalBitMask, uncompressedData); + return deserialize(chunkX, chunkZ, fullChunk, this.hasSkyLight, primaryBitMask, additionalBitMask, uncompressedData); } @Override - public void write(ByteBuf byteBuf, ClientWorld clientWorld, Chunk chunk) throws Exception { + public void write(ByteBuf byteBuf, Chunk chunk) throws Exception { final Pair chunkData = serialize(chunk); final byte[] data = chunkData.key(); final short additionalBitMask = chunkData.value(); @@ -120,7 +112,7 @@ public class ChunkType1_7_6 extends PartialType { byteBuf.writeShort(chunk.getBitmask()); byteBuf.writeShort(additionalBitMask); byteBuf.writeInt(compressedSize); - this.writeUnusedInt(byteBuf, clientWorld, chunk); + this.writeUnusedInt(byteBuf, chunk); byteBuf.writeBytes(compressedData, 0, compressedSize); } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ItemType.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ItemType.java index a847300..34a1f89 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ItemType.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/ItemType.java @@ -24,11 +24,8 @@ import io.netty.buffer.ByteBuf; public class ItemType extends Type { - private final boolean compressed; - - public ItemType(boolean compressed) { + public ItemType() { super(Item.class); - this.compressed = compressed; } @Override @@ -42,7 +39,7 @@ public class ItemType extends Type { item.setIdentifier(id); item.setAmount(buffer.readByte()); item.setData(buffer.readShort()); - item.setTag((this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).read(buffer)); + item.setTag(Types1_7_6.COMPRESSED_NBT.read(buffer)); return item; } @@ -54,7 +51,7 @@ public class ItemType extends Type { buffer.writeShort(item.identifier()); buffer.writeByte(item.amount()); buffer.writeShort(item.data()); - (this.compressed ? Types1_7_6.COMPRESSED_NBT : Types1_7_6.NBT).write(buffer, item.tag()); + Types1_7_6.COMPRESSED_NBT.write(buffer, item.tag()); } } diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Types1_7_6.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Types1_7_6.java index a8df5c1..d8c65ec 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Types1_7_6.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/Types1_7_6.java @@ -18,6 +18,7 @@ package net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; +import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; @@ -34,10 +35,7 @@ public class Types1_7_6 { public static final Type NBT = new NBTType(false); public static final Type COMPRESSED_NBT = new NBTType(true); - public static final Type ITEM = new ItemType(false); - public static final Type COMPRESSED_ITEM = new ItemType(true); - - public static final Type ITEM_ARRAY = new ItemArrayType<>(ITEM); + public static final Type COMPRESSED_ITEM = new ItemType(); public static final Type COMPRESSED_ITEM_ARRAY = new ItemArrayType<>(COMPRESSED_ITEM); public static final Type METADATA = new MetadataType(); @@ -50,4 +48,13 @@ public class Types1_7_6 { public static final Type POSITION_SHORT = new PositionVarYType<>(Type.SHORT, i -> (short) i); public static final Type POSITION_INT = new PositionVarYType<>(Type.INT, i -> i); + private static final ChunkType1_7_6 CHUNK_WITH_SKYLIGHT = new ChunkType1_7_6(true); + private static final ChunkType1_7_6 CHUNK_WITHOUT_SKYLIGHT = new ChunkType1_7_6(false); + + public static final BulkChunkType1_7_6 CHUNK_BULK = new BulkChunkType1_7_6(); + + public static ChunkType1_7_6 getChunk(Environment environment) { + return environment == Environment.NORMAL ? CHUNK_WITH_SKYLIGHT : CHUNK_WITHOUT_SKYLIGHT; + } + }