Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
WIP: Move the TileEntities writer to the 1.9 transformer.
Dieser Commit ist enthalten in:
Ursprung
ac1b35379e
Commit
4c9c50f939
@ -83,6 +83,27 @@ public class PacketWrapper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a type is at an index
|
||||||
|
*
|
||||||
|
* @param type The type of the part you wish to get.
|
||||||
|
* @param index The index of the part (relative to the type)
|
||||||
|
* @return True if the type is at the index
|
||||||
|
*/
|
||||||
|
public boolean isReadable(Type type, int index) {
|
||||||
|
int currentIndex = 0;
|
||||||
|
for (Pair<Type, Object> packetValue : readableObjects) {
|
||||||
|
if (packetValue.getKey().getBaseClass() == type.getBaseClass()) { // Ref check
|
||||||
|
if (currentIndex == index) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
currentIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a currently existing part in the output
|
* Set a currently existing part in the output
|
||||||
*
|
*
|
||||||
|
@ -45,8 +45,6 @@ public class FakeTileEntity {
|
|||||||
private static void register(Integer material, String name) {
|
private static void register(Integer material, String name) {
|
||||||
CompoundTag comp = new CompoundTag("");
|
CompoundTag comp = new CompoundTag("");
|
||||||
comp.put(new StringTag(name));
|
comp.put(new StringTag(name));
|
||||||
// for (Tag tag : tags)
|
|
||||||
// comp.put(tag);
|
|
||||||
tileEntities.put(material, comp);
|
tileEntities.put(material, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,13 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
|
|||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
|
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;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.ChunkType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
||||||
@Override
|
@Override
|
||||||
@ -60,19 +67,44 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* // Chunk packet TODO uncomment when it's no longer hardcoded in 1.8
|
// Chunk packet
|
||||||
registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() {
|
registerOutgoing(State.PLAY, 0x20, 0x20, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(new PacketHandler() {
|
handler(new PacketHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
wrapper.passthroughAll();
|
ClientChunks clientChunks = wrapper.user().get(ClientChunks.class);
|
||||||
|
|
||||||
|
ChunkType type = new ChunkType(clientChunks);
|
||||||
|
if (wrapper.isReadable(type, 0)) {
|
||||||
|
Chunk1_9to1_8 chunk = (Chunk1_9to1_8) wrapper.read(type);
|
||||||
|
|
||||||
|
List<CompoundTag> tags = new ArrayList<>();
|
||||||
|
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||||
|
ChunkSection1_9to1_8 section = chunk.getSections()[i];
|
||||||
|
if (section == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
// NOT SURE WHY Y AND Z WORK THIS WAY, TODO: WORK OUT WHY THIS IS OR FIX W/E BROKE IT
|
||||||
|
tags.add(FakeTileEntity.getFromBlock(x + (chunk.getX() << 4), z + (i << 4), y + (chunk.getZ() << 4), block));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0]));
|
||||||
|
} else {
|
||||||
wrapper.write(Type.VAR_INT, 0);
|
wrapper.write(Type.VAR_INT, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});*/
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,12 +3,10 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||||
import us.myles.ViaVersion.api.type.PartialType;
|
import us.myles.ViaVersion.api.type.PartialType;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType;
|
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.Chunk1_9to1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.ChunkSection1_9to1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chunks.ChunkSection1_9to1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||||
@ -16,16 +14,14 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
||||||
/**
|
/**
|
||||||
* Amount of sections in a chunks.
|
* Amount of sections in a chunks.
|
||||||
*/
|
*/
|
||||||
private static final int SECTION_COUNT = 16;
|
public static final int SECTION_COUNT = 16;
|
||||||
/**
|
/**
|
||||||
* size of each chunks section (16x16x16).
|
* size of each chunks section (16x16x16).
|
||||||
*/
|
*/
|
||||||
@ -150,23 +146,12 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
|||||||
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
|
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
|
||||||
Type.VAR_INT.write(output, chunk.getPrimaryBitmask());
|
Type.VAR_INT.write(output, chunk.getPrimaryBitmask());
|
||||||
|
|
||||||
List<CompoundTag> tags = new ArrayList<>();
|
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.buffer();
|
ByteBuf buf = Unpooled.buffer();
|
||||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||||
ChunkSection1_9to1_8 section = chunk.getSections()[i];
|
ChunkSection1_9to1_8 section = chunk.getSections()[i];
|
||||||
if (section == null) continue; // Section not set
|
if (section == null) continue; // Section not set
|
||||||
section.writeBlocks(buf);
|
section.writeBlocks(buf);
|
||||||
section.writeBlockLight(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)) {
|
|
||||||
// NOT SURE WHY Y AND Z WORK THIS WAY, TODO: WORK OUT WHY THIS IS OR FIX W/E BROKE IT
|
|
||||||
tags.add(FakeTileEntity.getFromBlock(x + (chunk.getX() << 4), z + (i << 4), y + (chunk.getZ() << 4), block));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||||
section.writeSkyLight(buf);
|
section.writeSkyLight(buf);
|
||||||
@ -182,7 +167,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
|||||||
output.writeBytes(chunk.getBiomeData());
|
output.writeBytes(chunk.getBiomeData());
|
||||||
}
|
}
|
||||||
|
|
||||||
Type.NBT_ARRAY.write(output, tags.toArray(new CompoundTag[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren