Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +01:00
Experimental implementation for block entities into chunks
Dieser Commit ist enthalten in:
Ursprung
b3612a68b0
Commit
f5b49bc9ce
@ -10,8 +10,7 @@ import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.type.types.*;
|
||||
import us.myles.ViaVersion.api.type.types.minecraft.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@ -61,6 +60,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
public static final Type<EulerAngle> ROTATION = new EulerAngleType();
|
||||
public static final Type<Vector> VECTOR = new VectorType();
|
||||
public static final Type<CompoundTag> NBT = new NBTType();
|
||||
public static final Type<List<CompoundTag>> NBT_ARRAY = new NBTArrayType();
|
||||
|
||||
public static final Type<UUID> OPTIONAL_UUID = new OptUUIDType();
|
||||
public static final Type<Position> OPTIONAL_POSITION = new OptPositionType();
|
||||
|
@ -0,0 +1,33 @@
|
||||
package us.myles.ViaVersion.api.type.types.minecraft;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NBTArrayType extends Type<List<CompoundTag>> {
|
||||
public NBTArrayType() {
|
||||
super("NBT Array", List.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompoundTag> read(ByteBuf buffer) throws Exception {
|
||||
int amount = Type.VAR_INT.read(buffer);
|
||||
|
||||
List<CompoundTag> nbtData = new ArrayList<>();
|
||||
for (int i = 0; i < amount; i++)
|
||||
nbtData.add(Type.NBT.read(buffer));
|
||||
|
||||
return nbtData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, List<CompoundTag> list) throws Exception {
|
||||
Type.VAR_INT.write(buffer, list.size());
|
||||
|
||||
for (CompoundTag tag : list)
|
||||
Type.NBT.write(buffer, tag);
|
||||
}
|
||||
}
|
@ -94,12 +94,17 @@ public class FakeTileEntity {
|
||||
register(m.getId(), name, tags);
|
||||
}
|
||||
|
||||
public static boolean hasBlock(int block) {
|
||||
return tileEntities.containsKey(block);
|
||||
}
|
||||
|
||||
public static CompoundTag getFromBlock(int x, int y, int z, int block) {
|
||||
if (tileEntities.containsKey(block)) {
|
||||
CompoundTag tag = tileEntities.get(block).clone();
|
||||
tag.put(new IntTag("x", x));
|
||||
tag.put(new IntTag("y", y));
|
||||
tag.put(new IntTag("z", z));
|
||||
System.out.println("Found tile entity " + block + " at position " + x + " " + y + " " + z);
|
||||
return tag;
|
||||
}
|
||||
return null;
|
||||
|
@ -60,7 +60,7 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
||||
}
|
||||
});
|
||||
|
||||
// Chunk packet
|
||||
/* // Chunk packet TODO uncomment when it's no longer hardcoded in 1.8
|
||||
registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@ -72,7 +72,7 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,10 +3,12 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
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_3to1_9_1_2.FakeTileEntity;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.Chunk1_9to1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.ChunkSection1_9to1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||
@ -14,7 +16,9 @@ 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.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
||||
@ -145,14 +149,25 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
||||
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
|
||||
Type.VAR_INT.write(output, chunk.getPrimaryBitmask());
|
||||
|
||||
List<CompoundTag> tags = new ArrayList<>();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||
ChunkSection1_9to1_8 section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
section.writeBlocks(buf);
|
||||
section.writeBlockLight(buf);
|
||||
for (int x = 0; x < 16; x++)
|
||||
for (int y = 0; y < 16; y++)
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int block = section.getBlockId(x, y, z);
|
||||
if (FakeTileEntity.hasBlock(block))
|
||||
tags.add(FakeTileEntity.getFromBlock(x * chunk.getX(), y, z * chunk.getZ(), block));
|
||||
}
|
||||
|
||||
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.hasBiomeData() ? 256 : 0));
|
||||
@ -163,6 +178,8 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
||||
if (chunk.hasBiomeData()) {
|
||||
output.writeBytes(chunk.getBiomeData());
|
||||
}
|
||||
|
||||
Type.NBT_ARRAY.write(buf, tags);
|
||||
}
|
||||
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren