Better support for nbt arrays rereading in chunks

This commit is contained in:
Myles 2017-05-17 19:43:48 +01:00
parent 2bd03ad92c
commit 21eb824395
4 changed files with 11 additions and 16 deletions

View File

@ -17,7 +17,6 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks.FakeTileEntit
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;
import java.util.ArrayList;
import java.util.List;
public class Protocol1_9_3TO1_9_1_2 extends Protocol {
@ -80,7 +79,7 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
Chunk1_9_1_2Type type = new Chunk1_9_1_2Type(clientWorld);
Chunk chunk = wrapper.passthrough(type);
List<CompoundTag> tags = new ArrayList<>();
List<CompoundTag> tags = chunk.getBlockEntities();
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
@ -98,7 +97,8 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
}
}
wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0]));
// Send (for clients on this version)
wrapper.write(Type.NBT_ARRAY, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
});
}

View File

@ -16,7 +16,7 @@ public class Chunk1_9_1_2 implements Chunk {
private int bitmask;
private final ChunkSection1_9_1_2[] sections;
private byte[] biomeData;
List<CompoundTag> blockEntities;
private List<CompoundTag> blockEntities;
public boolean isBiomeData() {
return biomeData != null;

View File

@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor;
import lombok.ToString;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
@RequiredArgsConstructor
@ -19,6 +19,7 @@ public class Chunk1_9to1_8 implements Chunk {
private final int primaryBitmask;
private final ChunkSection1_9to1_8[] sections;
private final byte[] biomeData;
private final List<CompoundTag> blockEntities;
private boolean unloadPacket = false;
/**
@ -28,7 +29,8 @@ public class Chunk1_9to1_8 implements Chunk {
* @param z coord
*/
public Chunk1_9to1_8(int x, int z) {
this(x, z, true, 0, new ChunkSection1_9to1_8[16], null);
this(x, z, true, 0, new ChunkSection1_9to1_8[16], null,
new ArrayList<CompoundTag>());
this.unloadPacket = true;
}
@ -50,9 +52,4 @@ public class Chunk1_9to1_8 implements Chunk {
public int getBitmask() {
return primaryBitmask;
}
@Override
public List<CompoundTag> getBlockEntities() {
return Collections.emptyList();
}
}

View File

@ -1,5 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import us.myles.ViaVersion.api.Via;
@ -16,6 +17,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.logging.Level;
@ -137,7 +139,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
}
// Return chunks
return new Chunk1_9to1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData);
return new Chunk1_9to1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList<CompoundTag>());
}
@Override
@ -172,9 +174,5 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
if (chunk.hasBiomeData()) {
output.writeBytes(chunk.getBiomeData());
}
}
}