Skip to content

Commit

Permalink
Move Chunk type instances into protocol versioned type classes
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 20, 2023
1 parent 5ab8093 commit d73c128
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

public class BulkChunkType1_7_6 extends Type<Chunk[]> {

public static final BulkChunkType1_7_6 TYPE = new BulkChunkType1_7_6();

public BulkChunkType1_7_6() {
super(Chunk[].class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,19 +34,13 @@

public class ChunkType1_7_6 extends Type<Chunk> {

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) {
super(Chunk.class);
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,4 +51,12 @@ public class Types1_7_6 {
public static final Type<Position> POSITION_SHORT = new PositionVarYType<>(Type.SHORT, i -> (short) i);
public static final Type<Position> 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;
}
}

0 comments on commit d73c128

Please sign in to comment.