mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-29 05:26:23 +01:00
Cleanup code
This commit is contained in:
parent
667ad0d059
commit
3b1341f2b3
@ -18,7 +18,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_9;
|
|||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_11to1_10.packets.InventoryPackets;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker;
|
import us.myles.ViaVersion.protocols.protocol1_11to1_10.storage.EntityTracker;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_11to1_10.types.Chunk1_11Type;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
|
||||||
public class Protocol1_11To1_10 extends Protocol {
|
public class Protocol1_11To1_10 extends Protocol {
|
||||||
@ -277,7 +277,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
|||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||||
|
|
||||||
Chunk1_11Type type = new Chunk1_11Type(clientWorld);
|
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
|
||||||
Chunk chunk = wrapper.passthrough(type);
|
Chunk chunk = wrapper.passthrough(type);
|
||||||
|
|
||||||
if (chunk.getBlockEntities() == null) return;
|
if (chunk.getBlockEntities() == null) return;
|
||||||
|
@ -1,103 +0,0 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_11to1_10.types;
|
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.Environment;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
|
||||||
import us.myles.ViaVersion.api.type.PartialType;
|
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
|
||||||
import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.Chunk1_9_3_4;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.ChunkSection1_9_3_4;
|
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.BitSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Chunk1_11Type extends PartialType<Chunk, ClientWorld> {
|
|
||||||
|
|
||||||
public Chunk1_11Type(ClientWorld param) {
|
|
||||||
super(param, Chunk.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
|
|
||||||
int chunkX = input.readInt();
|
|
||||||
int chunkZ = input.readInt();
|
|
||||||
|
|
||||||
boolean groundUp = input.readBoolean();
|
|
||||||
int primaryBitmask = Type.VAR_INT.read(input);
|
|
||||||
Type.VAR_INT.read(input);
|
|
||||||
|
|
||||||
BitSet usedSections = new BitSet(16);
|
|
||||||
ChunkSection1_9_3_4[] sections = new ChunkSection1_9_3_4[16];
|
|
||||||
// Calculate section count from bitmask
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
if ((primaryBitmask & (1 << i)) != 0) {
|
|
||||||
usedSections.set(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read sections
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
if (!usedSections.get(i)) continue; // Section not set
|
|
||||||
ChunkSection1_9_3_4 section = new ChunkSection1_9_3_4();
|
|
||||||
sections[i] = section;
|
|
||||||
section.readBlocks(input);
|
|
||||||
section.readBlockLight(input);
|
|
||||||
if (world.getEnvironment() == Environment.NORMAL) {
|
|
||||||
section.readSkyLight(input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] biomeData = groundUp ? new byte[256] : null;
|
|
||||||
if (groundUp) {
|
|
||||||
input.readBytes(biomeData);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<CompoundTag> nbtData = Arrays.asList(Type.NBT_ARRAY.read(input));
|
|
||||||
|
|
||||||
return new Chunk1_9_3_4(chunkX, chunkZ, groundUp, primaryBitmask, sections, biomeData, nbtData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
|
|
||||||
output.writeInt(chunk.getX());
|
|
||||||
output.writeInt(chunk.getZ());
|
|
||||||
|
|
||||||
output.writeBoolean(chunk.isGroundUp());
|
|
||||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.buffer();
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
ChunkSection section = chunk.getSections()[i];
|
|
||||||
if (section == null) continue; // Section not set
|
|
||||||
section.writeBlocks(buf);
|
|
||||||
section.writeBlockLight(buf);
|
|
||||||
|
|
||||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
|
||||||
section.writeSkyLight(buf);
|
|
||||||
|
|
||||||
}
|
|
||||||
buf.readerIndex(0);
|
|
||||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
|
||||||
output.writeBytes(buf);
|
|
||||||
buf.release(); // release buffer
|
|
||||||
|
|
||||||
// Write biome data
|
|
||||||
if (chunk.isBiomeData()) {
|
|
||||||
output.writeBytes(chunk.getBiomeData());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write Block Entities
|
|
||||||
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<? extends Type> getBaseClass() {
|
|
||||||
return BaseChunkType.class;
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,6 +13,7 @@ import us.myles.ViaVersion.packets.State;
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.BlockEntity;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.chunks.BlockEntity;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type;
|
||||||
|
|
||||||
public class Protocol1_9_1_2TO1_9_3_4 extends Protocol {
|
public class Protocol1_9_1_2TO1_9_3_4 extends Protocol {
|
||||||
|
|
||||||
@ -62,9 +63,11 @@ public class Protocol1_9_1_2TO1_9_3_4 extends Protocol {
|
|||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||||
|
|
||||||
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
|
Chunk1_9_3_4Type newType = new Chunk1_9_3_4Type(clientWorld);
|
||||||
Chunk chunk = wrapper.passthrough(type);
|
Chunk1_9_1_2Type oldType = new Chunk1_9_1_2Type(clientWorld); // Get the old type to not write Block Entities
|
||||||
|
|
||||||
|
Chunk chunk = wrapper.read(newType);
|
||||||
|
wrapper.write(oldType, chunk);
|
||||||
BlockEntity.handle(chunk.getBlockEntities(), wrapper.user());
|
BlockEntity.handle(chunk.getBlockEntities(), wrapper.user());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -92,7 +92,8 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
|||||||
output.writeBytes(chunk.getBiomeData());
|
output.writeBytes(chunk.getBiomeData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't write block entities
|
// Write Block Entities
|
||||||
|
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user