From d73c1281f618a5a1290aaf9684c25ddf87ae42bf Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Fri, 20 Oct 2023 11:01:49 +0200 Subject: [PATCH] Move Chunk type instances into protocol versioned type classes --- .../Protocol1_4_6_7to1_4_4_5.java | 3 ++- .../types/Types1_4_4.java | 23 +++++++++++++++++++ .../Protocol1_8to1_7_6_10.java | 4 ++-- .../types/BulkChunkType1_7_6.java | 2 -- .../types/ChunkType1_7_6.java | 7 ------ .../types/Types1_7_6.java | 9 ++++++++ 6 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_4_6_7to1_4_4_5/types/Types1_4_4.java 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 5b62f4f..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 @@ -32,6 +32,7 @@ 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.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; @@ -128,7 +129,7 @@ public void register() { this.registerClientbound(ClientboundPackets1_4_4.MAP_BULK_CHUNK, new PacketHandlers() { @Override public void register() { - map(BulkChunkType1_7_6.TYPE, BulkChunkType1_4_4.TYPE); + 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/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..96d3839 --- /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,23 @@ +/* + * 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_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 e1a9a15..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 @@ -636,7 +636,7 @@ public void register() { handler(wrapper -> { final Environment environment = wrapper.user().get(ClientWorld.class).getEnvironment(); - final Chunk chunk = wrapper.read(ChunkType1_7_6.forEnvironment(environment)); + final Chunk chunk = wrapper.read(Types1_7_6.getChunk(environment)); wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk); wrapper.write(ChunkType1_8.forEnvironment(environment), chunk); }); @@ -699,7 +699,7 @@ public void register() { @Override public void register() { handler(wrapper -> { - final Chunk[] chunks = wrapper.read(BulkChunkType1_7_6.TYPE); + final Chunk[] chunks = wrapper.read(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/BulkChunkType1_7_6.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/BulkChunkType1_7_6.java index 9249c12..683630c 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/BulkChunkType1_7_6.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/types/BulkChunkType1_7_6.java @@ -31,8 +31,6 @@ public class BulkChunkType1_7_6 extends Type { - public static final BulkChunkType1_7_6 TYPE = new BulkChunkType1_7_6(); - public BulkChunkType1_7_6() { super(Chunk[].class); } 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 b163279..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,7 +17,6 @@ */ package net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types; -import com.viaversion.viaversion.api.minecraft.Environment; import com.viaversion.viaversion.api.minecraft.chunks.*; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.FixedByteArrayType; @@ -35,8 +34,6 @@ public class ChunkType1_7_6 extends Type { - private static final ChunkType1_7_6 WITH_SKYLIGHT = new ChunkType1_7_6(true); - private static final ChunkType1_7_6 WITHOUT_SKYLIGHT = new ChunkType1_7_6(false); private final boolean hasSkyLight; public ChunkType1_7_6(boolean hasSkyLight) { @@ -44,10 +41,6 @@ public ChunkType1_7_6(boolean hasSkyLight) { this.hasSkyLight = hasSkyLight; } - public static ChunkType1_7_6 forEnvironment(Environment environment) { - return environment == Environment.NORMAL ? WITH_SKYLIGHT : WITHOUT_SKYLIGHT; - } - /** * This method is here to allow overriding the code for 1.2.5 -{@literal >} 1.3.2 because it introduced an unused int * 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..b459477 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; @@ -50,4 +51,12 @@ 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 ChunkType1_7_6 getChunk(Environment environment) { + return environment == Environment.NORMAL ? CHUNK_WITH_SKYLIGHT : CHUNK_WITHOUT_SKYLIGHT; + } }