From 8ebc8c34f3a7cd173415a62378470df8bd1a2f37 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 20 Oct 2023 12:30:03 +1000 Subject: [PATCH] Reuse old chunk type instances, more type cleanup --- .../viaversion/api/minecraft/ClientWorld.java | 15 +++++-- .../type/types/chunk/BulkChunkType1_8.java | 34 +++++++-------- .../api/type/types/chunk/ChunkType1_13.java | 14 +++++-- .../api/type/types/chunk/ChunkType1_14.java | 8 +--- .../api/type/types/chunk/ChunkType1_15.java | 6 --- .../api/type/types/chunk/ChunkType1_16.java | 6 --- .../api/type/types/chunk/ChunkType1_16_2.java | 6 --- .../api/type/types/chunk/ChunkType1_17.java | 6 --- .../api/type/types/chunk/ChunkType1_18.java | 5 --- .../api/type/types/chunk/ChunkType1_20_2.java | 7 ---- .../api/type/types/chunk/ChunkType1_8.java | 15 +++---- .../api/type/types/chunk/ChunkType1_9_1.java | 15 +++---- .../api/type/types/chunk/ChunkType1_9_3.java | 19 +++++---- .../api/type/types/item/BaseItemType.java | 42 ------------------- .../types/item/ItemShortArrayType1_13_2.java | 9 ++-- .../types/item/ItemShortArrayType1_8.java | 9 ++-- .../api/type/types/item/ItemType1_13.java | 4 +- .../api/type/types/item/ItemType1_13_2.java | 13 +++--- .../api/type/types/item/ItemType1_20_2.java | 13 +++--- .../api/type/types/item/ItemType1_8.java | 9 ++-- .../api/type/types/math/PositionType1_14.java | 5 --- .../Protocol1_10To1_9_3_4.java | 4 +- .../Protocol1_11To1_10.java | 4 +- .../Protocol1_12To1_11_1.java | 4 +- .../Protocol1_13_1To1_13.java | 2 +- .../packets/WorldPackets.java | 2 +- .../Protocol1_13To1_12_2.java | 2 +- .../packets/WorldPackets.java | 4 +- .../Protocol1_14To1_13_2.java | 2 +- .../packets/WorldPackets.java | 4 +- .../packets/WorldPackets.java | 2 +- .../Protocol1_9_3To1_9_1_2.java | 4 +- .../protocol1_9to1_8/Protocol1_9To1_8.java | 2 +- .../packets/WorldPackets.java | 8 ++-- 34 files changed, 116 insertions(+), 188 deletions(-) delete mode 100644 api/src/main/java/com/viaversion/viaversion/api/type/types/item/BaseItemType.java diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/ClientWorld.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/ClientWorld.java index c1531ab40..d104e4a92 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/ClientWorld.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/ClientWorld.java @@ -22,25 +22,32 @@ */ package com.viaversion.viaversion.api.minecraft; -import com.viaversion.viaversion.api.connection.StoredObject; +import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.UserConnection; import org.checkerframework.checker.nullness.qual.Nullable; /** * Stored up until 1.14 to be used in chunk sending. */ -public class ClientWorld extends StoredObject { +public class ClientWorld implements StorableObject { private Environment environment; + @Deprecated/*(forRemoval = true)*/ public ClientWorld(final UserConnection connection) { - super(connection); + } + + public ClientWorld() { + } + + public ClientWorld(final Environment environment) { + this.environment = environment; } public @Nullable Environment getEnvironment() { return environment; } - public void setEnvironment(int environmentId) { + public void setEnvironment(final int environmentId) { this.environment = Environment.getEnvironmentById(environmentId); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java index a360b9e5e..80105e3f7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/BulkChunkType1_8.java @@ -24,29 +24,23 @@ package com.viaversion.viaversion.api.type.types.chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; -import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import io.netty.buffer.ByteBuf; -public class BulkChunkType1_8 extends PartialType { +public class BulkChunkType1_8 extends Type { + public static final Type TYPE = new BulkChunkType1_8(); private static final int BLOCKS_PER_SECTION = 16 * 16 * 16; private static final int BLOCKS_BYTES = BLOCKS_PER_SECTION * 2; private static final int LIGHT_BYTES = BLOCKS_PER_SECTION / 2; private static final int BIOME_BYTES = 16 * 16; - public BulkChunkType1_8(final ClientWorld clientWorld) { - super(clientWorld, Chunk[].class); + public BulkChunkType1_8() { + super(Chunk[].class); } @Override - public Class getBaseClass() { - return BaseChunkBulkType.class; - } - - @Override - public Chunk[] read(ByteBuf input, ClientWorld world) throws Exception { + public Chunk[] read(ByteBuf input) throws Exception { final boolean skyLight = input.readBoolean(); final int count = Type.VAR_INT.readPrimitive(input); final Chunk[] chunks = new Chunk[count]; @@ -67,11 +61,11 @@ public class BulkChunkType1_8 extends PartialType { } @Override - public void write(ByteBuf output, ClientWorld world, Chunk[] chunks) throws Exception { + public void write(ByteBuf output, Chunk[] chunks) throws Exception { boolean skyLight = false; loop1: - for (Chunk c : chunks) { - for (ChunkSection section : c.getSections()) { + for (Chunk chunk : chunks) { + for (ChunkSection section : chunk.getSections()) { if (section != null && section.getLight().hasSkyLight()) { skyLight = true; break loop1; @@ -82,14 +76,14 @@ public class BulkChunkType1_8 extends PartialType { Type.VAR_INT.writePrimitive(output, chunks.length); // Write metadata - for (Chunk c : chunks) { - output.writeInt(c.getX()); - output.writeInt(c.getZ()); - output.writeShort(c.getBitmask()); + for (Chunk chunk : chunks) { + output.writeInt(chunk.getX()); + output.writeInt(chunk.getZ()); + output.writeShort(chunk.getBitmask()); } // Write data - for (Chunk c : chunks) { - output.writeBytes(ChunkType1_8.serialize(c)); + for (Chunk chunk : chunks) { + output.writeBytes(ChunkType1_8.serialize(chunk)); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java index bcc6095a4..95e3b60de 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_13.java @@ -24,15 +24,14 @@ package com.viaversion.viaversion.api.type.types.chunk; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_13; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.Arrays; @@ -41,8 +40,15 @@ import java.util.logging.Level; public class ChunkType1_13 extends PartialType { - public ChunkType1_13(ClientWorld param) { - super(param, Chunk.class); + private static final ChunkType1_13 WITH_SKYLIGHT = new ChunkType1_13(new ClientWorld(Environment.NORMAL)); + private static final ChunkType1_13 WITHOUT_SKYLIGHT = new ChunkType1_13(new ClientWorld(Environment.NETHER)); + + public ChunkType1_13(ClientWorld clientWorld) { + super(clientWorld, Chunk.class); + } + + public static ChunkType1_13 forEnvironment(Environment environment) { + return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT; } @Override diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java index f3fa88bd8..3ea2c261f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_14.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_13; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -37,6 +36,8 @@ import java.util.List; public class ChunkType1_14 extends Type { + public static final Type TYPE = new ChunkType1_14(); + public ChunkType1_14() { super(Chunk.class); } @@ -118,9 +119,4 @@ public class ChunkType1_14 extends Type { // Write Block Entities Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java index 3a96fbcc8..8cf7b8198 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_13; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -119,9 +118,4 @@ public class ChunkType1_15 extends Type { // Write Block Entities Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java index 36f8d631f..39642580f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_16; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -121,9 +120,4 @@ public class ChunkType1_16 extends Type { // Write Block Entities Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java index 7ab7515f1..a2aa0a882 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_16; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -115,9 +114,4 @@ public class ChunkType1_16_2 extends Type { // Write Block Entities Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java index b036fc290..a4f221bc8 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_17.java @@ -29,7 +29,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_16; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -113,9 +112,4 @@ public final class ChunkType1_17 extends Type { // Write Block Entities Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java index 5beb494bd..12ea6f578 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_18.java @@ -97,9 +97,4 @@ public final class ChunkType1_18 extends Type { Type.BLOCK_ENTITY1_18.write(buffer, blockEntity); } } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java index 03b1c3322..8e2467776 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_20_2.java @@ -29,8 +29,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk1_18; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; -import com.viaversion.viaversion.api.type.types.chunk.ChunkSectionType1_18; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.List; @@ -96,9 +94,4 @@ public final class ChunkType1_20_2 extends Type { Type.BLOCK_ENTITY1_20_2.write(buffer, blockEntity); } } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java index 379729b26..9b27379ab 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_8.java @@ -22,28 +22,29 @@ */ package com.viaversion.viaversion.api.type.types.chunk; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_8; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.ArrayList; public class ChunkType1_8 extends PartialType { - public ChunkType1_8(ClientWorld param) { - super(param, Chunk.class); + private static final ChunkType1_8 WITH_SKYLIGHT = new ChunkType1_8(new ClientWorld(Environment.NORMAL)); + private static final ChunkType1_8 WITHOUT_SKYLIGHT = new ChunkType1_8(new ClientWorld(Environment.NETHER)); + + public ChunkType1_8(ClientWorld clientWorld) { + super(clientWorld, Chunk.class); } - @Override - public Class getBaseClass() { - return BaseChunkType.class; + public static ChunkType1_8 forEnvironment(Environment environment) { + return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT; } @Override diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java index 330014765..f5de15b1e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_1.java @@ -22,25 +22,31 @@ */ package com.viaversion.viaversion.api.type.types.chunk; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_9; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.BitSet; public class ChunkType1_9_1 extends PartialType { + private static final ChunkType1_9_1 WITH_SKYLIGHT = new ChunkType1_9_1(new ClientWorld(Environment.NORMAL)); + private static final ChunkType1_9_1 WITHOUT_SKYLIGHT = new ChunkType1_9_1(new ClientWorld(Environment.NETHER)); + public ChunkType1_9_1(ClientWorld clientWorld) { super(clientWorld, Chunk.class); } + public static ChunkType1_9_1 forEnvironment(Environment environment) { + return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT; + } + @Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); @@ -115,9 +121,4 @@ public class ChunkType1_9_1 extends PartialType { } } } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java index 40da56fab..a60cd4c4b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_9_3.java @@ -24,15 +24,14 @@ package com.viaversion.viaversion.api.type.types.chunk; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.chunk.BaseChunkType; import com.viaversion.viaversion.api.type.types.version.Types1_9; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import io.netty.buffer.ByteBuf; import java.util.ArrayList; import java.util.Arrays; @@ -40,8 +39,15 @@ import java.util.List; public class ChunkType1_9_3 extends PartialType { - public ChunkType1_9_3(ClientWorld param) { - super(param, Chunk.class); + private static final ChunkType1_9_3 WITH_SKYLIGHT = new ChunkType1_9_3(new ClientWorld(Environment.NORMAL)); + private static final ChunkType1_9_3 WITHOUT_SKYLIGHT = new ChunkType1_9_3(new ClientWorld(Environment.NETHER)); + + public ChunkType1_9_3(ClientWorld clientWorld) { + super(clientWorld, Chunk.class); + } + + public static ChunkType1_9_3 forEnvironment(Environment environment) { + return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT; } @Override @@ -122,9 +128,4 @@ public class ChunkType1_9_3 extends PartialType { // Write Block Entities Type.NAMED_COMPOUND_TAG_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); } - - @Override - public Class getBaseClass() { - return BaseChunkType.class; - } } \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/BaseItemType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/BaseItemType.java deleted file mode 100644 index ac98d151e..000000000 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/BaseItemType.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2023 ViaVersion and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.viaversion.viaversion.api.type.types.item; - -import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.api.type.Type; - -abstract class BaseItemType extends Type { - - protected BaseItemType() { - super(Item.class); - } - - protected BaseItemType(String typeName) { - super(typeName, Item.class); - } - - @Override - public Class getBaseClass() { - return BaseItemType.class; - } -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java index 1508a63fe..16299c8f5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_13_2.java @@ -23,6 +23,7 @@ package com.viaversion.viaversion.api.type.types.item; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_13_2 extends BaseItemArrayType { @@ -33,19 +34,19 @@ public class ItemShortArrayType1_13_2 extends BaseItemArrayType { @Override public Item[] read(ByteBuf buffer) throws Exception { - int amount = SHORT.readPrimitive(buffer); + int amount = Type.SHORT.readPrimitive(buffer); Item[] array = new Item[amount]; for (int i = 0; i < amount; i++) { - array[i] = ITEM1_13_2.read(buffer); + array[i] = Type.ITEM1_13_2.read(buffer); } return array; } @Override public void write(ByteBuf buffer, Item[] object) throws Exception { - SHORT.writePrimitive(buffer, (short) object.length); + Type.SHORT.writePrimitive(buffer, (short) object.length); for (Item o : object) { - ITEM1_13_2.write(buffer, o); + Type.ITEM1_13_2.write(buffer, o); } } } \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java index be35a5f27..346451977 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemShortArrayType1_8.java @@ -23,6 +23,7 @@ package com.viaversion.viaversion.api.type.types.item; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; public class ItemShortArrayType1_8 extends BaseItemArrayType { @@ -33,19 +34,19 @@ public class ItemShortArrayType1_8 extends BaseItemArrayType { @Override public Item[] read(ByteBuf buffer) throws Exception { - int amount = SHORT.readPrimitive(buffer); + int amount = Type.SHORT.readPrimitive(buffer); Item[] array = new Item[amount]; for (int i = 0; i < amount; i++) { - array[i] = ITEM1_8.read(buffer); + array[i] = Type.ITEM1_8.read(buffer); } return array; } @Override public void write(ByteBuf buffer, Item[] object) throws Exception { - SHORT.writePrimitive(buffer, (short) object.length); + Type.SHORT.writePrimitive(buffer, (short) object.length); for (Item o : object) { - ITEM1_8.write(buffer, o); + Type.ITEM1_8.write(buffer, o); } } } \ No newline at end of file diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java index 725014ebf..a810e1921 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13.java @@ -28,9 +28,9 @@ import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class ItemType1_13 extends BaseItemType { +public class ItemType1_13 extends Type { public ItemType1_13() { - super("FlatItem"); + super("FlatItem", Item.class); } @Override diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java index 87542e662..b0ca34906 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_13_2.java @@ -24,12 +24,13 @@ package com.viaversion.viaversion.api.type.types.item; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class ItemType1_13_2 extends BaseItemType { +public class ItemType1_13_2 extends Type { public ItemType1_13_2() { - super("FlatVarIntItem"); + super("FlatVarIntItem", Item.class); } @Override @@ -39,9 +40,9 @@ public class ItemType1_13_2 extends BaseItemType { return null; } else { Item item = new DataItem(); - item.setIdentifier(VAR_INT.readPrimitive(buffer)); + item.setIdentifier(Type.VAR_INT.readPrimitive(buffer)); item.setAmount(buffer.readByte()); - item.setTag(NAMED_COMPOUND_TAG.read(buffer)); + item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer)); return item; } } @@ -52,9 +53,9 @@ public class ItemType1_13_2 extends BaseItemType { buffer.writeBoolean(false); } else { buffer.writeBoolean(true); - VAR_INT.writePrimitive(buffer, object.identifier()); + Type.VAR_INT.writePrimitive(buffer, object.identifier()); buffer.writeByte(object.amount()); - NAMED_COMPOUND_TAG.write(buffer, object.tag()); + Type.NAMED_COMPOUND_TAG.write(buffer, object.tag()); } } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java index 9af635745..5cd44dd22 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_2.java @@ -24,13 +24,14 @@ package com.viaversion.viaversion.api.type.types.item; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class ItemType1_20_2 extends BaseItemType { +public class ItemType1_20_2 extends Type { public ItemType1_20_2() { - super("ItemType1_20_2"); + super("ItemType1_20_2", Item.class); } @Override @@ -40,9 +41,9 @@ public class ItemType1_20_2 extends BaseItemType { } final Item item = new DataItem(); - item.setIdentifier(VAR_INT.readPrimitive(buffer)); + item.setIdentifier(Type.VAR_INT.readPrimitive(buffer)); item.setAmount(buffer.readByte()); - item.setTag(COMPOUND_TAG.read(buffer)); + item.setTag(Type.COMPOUND_TAG.read(buffer)); return item; } @@ -52,9 +53,9 @@ public class ItemType1_20_2 extends BaseItemType { buffer.writeBoolean(false); } else { buffer.writeBoolean(true); - VAR_INT.writePrimitive(buffer, object.identifier()); + Type.VAR_INT.writePrimitive(buffer, object.identifier()); buffer.writeByte(object.amount()); - COMPOUND_TAG.write(buffer, object.tag()); + Type.COMPOUND_TAG.write(buffer, object.tag()); } } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java index 066ca32d4..721f40927 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_8.java @@ -24,13 +24,14 @@ package com.viaversion.viaversion.api.type.types.item; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.type.Type; import io.netty.buffer.ByteBuf; import org.checkerframework.checker.nullness.qual.Nullable; -public class ItemType1_8 extends BaseItemType { +public class ItemType1_8 extends Type { public ItemType1_8() { - super("Item"); + super("Item", Item.class); } @Override @@ -43,7 +44,7 @@ public class ItemType1_8 extends BaseItemType { item.setIdentifier(id); item.setAmount(buffer.readByte()); item.setData(buffer.readShort()); - item.setTag(NAMED_COMPOUND_TAG.read(buffer)); + item.setTag(Type.NAMED_COMPOUND_TAG.read(buffer)); return item; } } @@ -56,7 +57,7 @@ public class ItemType1_8 extends BaseItemType { buffer.writeShort(object.identifier()); buffer.writeByte(object.amount()); buffer.writeShort(object.data()); - NAMED_COMPOUND_TAG.write(buffer, object.tag()); + Type.NAMED_COMPOUND_TAG.write(buffer, object.tag()); } } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/PositionType1_14.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/PositionType1_14.java index 5e890e3cf..9afd47516 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/math/PositionType1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/math/PositionType1_14.java @@ -50,11 +50,6 @@ public class PositionType1_14 extends Type { | ((((long) object.z()) & 0x3ffffff) << 12)); } - @Override - public Class getBaseClass() { - return PositionType1_8.class; - } - public static final class OptionalPosition1_14Type extends OptionalType { public OptionalPosition1_14Type() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java index f78560847..8f22d4a1b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java @@ -179,7 +179,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk chunk = wrapper.passthrough(new ChunkType1_9_3(clientWorld)); + Chunk chunk = wrapper.passthrough(ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment())); if (Via.getConfig().isReplacePistons()) { int replacementId = Via.getConfig().getPistonReplacementId(); @@ -237,7 +237,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk chunk = wrapper.passthrough(new ChunkType1_9_3(clientWorld)); + Chunk chunk = wrapper.passthrough(ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment())); if (chunk.getBlockEntities() == null) return; for (CompoundTag tag : chunk.getBlockEntities()) { @@ -346,7 +346,7 @@ public class Protocol1_11To1_10 extends AbstractProtocol { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - ChunkType1_9_3 type = new ChunkType1_9_3(clientWorld); + ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); Chunk chunk = wrapper.passthrough(type); for (int s = 0; s < chunk.getSections().length; s++) { @@ -245,7 +245,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk chunk = wrapper.passthrough(new ChunkType1_13(clientWorld)); + Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment())); for (ChunkSection section : chunk.getSections()) { if (section == null) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 68d2db5de..0308afdfd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -865,7 +865,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk chunk = wrapper.read(new ChunkType1_13(clientWorld)); - wrapper.write(new ChunkType1_14(), chunk); + Chunk chunk = wrapper.read(ChunkType1_13.forEnvironment(clientWorld.getEnvironment())); + wrapper.write(ChunkType1_14.TYPE, chunk); int[] motionBlocking = new int[16 * 16]; int[] worldSurface = new int[16 * 16]; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java index 720a0e2cb..b7f8eead7 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java @@ -40,7 +40,7 @@ public final class WorldPackets { blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_14_4.ACKNOWLEDGE_PLAYER_DIGGING); protocol.registerClientbound(ClientboundPackets1_14_4.CHUNK_DATA, wrapper -> { - Chunk chunk = wrapper.read(new ChunkType1_14()); + Chunk chunk = wrapper.read(ChunkType1_14.TYPE); wrapper.write(new ChunkType1_15(), chunk); if (chunk.isFullChunk()) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java index a17eb77b9..e0e996b47 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3To1_9_1_2.java @@ -87,8 +87,8 @@ public class Protocol1_9_3To1_9_1_2 extends AbstractProtocol { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - Chunk chunk = wrapper.read(new ChunkType1_9_1(clientWorld)); - wrapper.write(new ChunkType1_9_3(clientWorld), chunk); + Chunk chunk = wrapper.read(ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment())); + wrapper.write(ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()), chunk); List tags = chunk.getBlockEntities(); for (int s = 0; s < chunk.getSections().length; s++) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java index d4e7322e1..012d24d12 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java @@ -148,7 +148,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); - Chunk chunk = wrapper.read(new ChunkType1_8(clientWorld)); + Chunk chunk = wrapper.read(ChunkType1_8.forEnvironment(clientWorld.getEnvironment())); long chunkHash = ClientChunks.toLong(chunk.getX(), chunk.getZ()); @@ -152,7 +152,7 @@ public class WorldPackets { } } } else { - Type chunkType = new ChunkType1_9_1(clientWorld); + Type chunkType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment()); wrapper.write(chunkType, chunk); clientChunks.getLoadedChunks().add(chunkHash); @@ -177,9 +177,9 @@ public class WorldPackets { wrapper.cancel(); // Cancel the packet from being sent ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); - Chunk[] chunks = wrapper.read(new BulkChunkType1_8(clientWorld)); + Chunk[] chunks = wrapper.read(BulkChunkType1_8.TYPE); - Type chunkType = new ChunkType1_9_1(clientWorld); + Type chunkType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment()); // Split into multiple chunk packets for (Chunk chunk : chunks) { PacketWrapper chunkData = wrapper.create(ClientboundPackets1_9.CHUNK_DATA);