From 47980bfe16622dc949ba9d0471ad53aa501957c5 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:14:00 +0200 Subject: [PATCH] Deleted unused type instances and cleaned up some protocols --- .../protocol1_0_0_1tob1_8_0_1/types/Typesb1_8_0_1.java | 2 -- .../Protocol1_3_1_2to1_2_4_5.java | 4 ++-- .../protocol1_3_1_2to1_2_4_5/types/ItemType.java | 9 +++------ .../protocol1_3_1_2to1_2_4_5/types/Types1_2_4.java | 5 +---- .../protocol1_4_2to1_3_1_2/types/Types1_3_1.java | 1 - .../protocol1_4_6_7to1_4_4_5/types/Types1_4_4.java | 1 + .../protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java | 4 ++-- .../release/protocol1_8to1_7_6_10/types/ItemType.java | 9 +++------ .../protocol1_8to1_7_6_10/types/Types1_7_6.java | 10 ++++------ 9 files changed, 16 insertions(+), 29 deletions(-) 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 @@ 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/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 86cecd6..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 void register() { if (!load) { final Chunk chunk = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>()); - wrapper.write(ChunkType1_7_6.forEnvironment(wrapper.user().get(ClientWorld.class).getEnvironment()), chunk); + wrapper.write(Types1_7_6.getChunk(wrapper.user().get(ClientWorld.class).getEnvironment()), chunk); } else { wrapper.cancel(); } @@ -496,7 +496,7 @@ public void register() { } } } - wrapper.write(ChunkType1_7_6.forEnvironment(environment), chunk); + wrapper.write(Types1_7_6.getChunk(environment), chunk); }); } }); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/ItemType.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/ItemType.java index 9b704ca..a4246a5 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/ItemType.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_3_1_2to1_2_4_5/types/ItemType.java @@ -26,11 +26,8 @@ public class ItemType extends Type { - 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 Item read(ByteBuf buffer) throws Exception { 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 void write(ByteBuf buffer, Item item) throws Exception { 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 @@ 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 @@ 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/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 index 96d3839..a34d49e 100644 --- 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 @@ -20,4 +20,5 @@ 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 80d7387..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 @@ -421,7 +421,7 @@ public void register() { @Override public void register() { handler(wrapper -> { - final Chunk chunk = wrapper.passthrough(ChunkType1_7_6.forEnvironment(wrapper.user().get(ClientWorld.class).getEnvironment())); + 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 void register() { @Override public void register() { handler(wrapper -> { - final Chunk[] chunks = wrapper.passthrough(BulkChunkType1_7_6.TYPE); + 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/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 @@ 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 Item read(ByteBuf buffer) throws Exception { 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 void write(ByteBuf buffer, Item item) throws Exception { 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 b459477..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 @@ -35,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(); @@ -51,12 +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); - public static final BulkChunkType1_7_6 CHUNK_BULK = new BulkChunkType1_7_6(); - 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; } + }