use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage in project DirtMultiversion by DirtPowered.
the class RotationUtil method fixBlockRotation.
public static byte fixBlockRotation(ServerSession session, int startX, int startY, int startZ) {
BlockStorage blockStorage = session.getUserData().getProtocolStorage().get(BlockStorage.class);
byte blockData = 3;
if (blockStorage == null) {
return blockData;
}
int rot1 = blockStorage.getBlockAt(startX, startY, startZ - 1);
int rot2 = blockStorage.getBlockAt(startX, startY, startZ + 1);
int rot3 = blockStorage.getBlockAt(startX - 1, startY, startZ);
int rot4 = blockStorage.getBlockAt(startX + 1, startY, startZ);
int rot5;
if (rot3 == CHEST_BLOCK) {
rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ - 1);
} else {
rot5 = blockStorage.getBlockAt(startX + 1, startY, startZ - 1);
}
int rot6;
if (rot3 == CHEST_BLOCK) {
rot6 = blockStorage.getBlockAt(startX - 1, startY, startZ + 1);
} else {
rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ + 1);
}
if (rot1 != CHEST_BLOCK && rot2 != CHEST_BLOCK) {
if (rot3 != CHEST_BLOCK && rot4 != CHEST_BLOCK) {
if (SolidBlockList.isSolid(rot2) && !SolidBlockList.isSolid(rot1)) {
blockData = 2;
}
if (SolidBlockList.isSolid(rot3) && !SolidBlockList.isSolid(rot4)) {
blockData = 5;
}
if (SolidBlockList.isSolid(rot4) && !SolidBlockList.isSolid(rot3)) {
blockData = 4;
}
} else {
if (SolidBlockList.isSolid(rot2) || SolidBlockList.isSolid(rot6)) {
if (!SolidBlockList.isSolid(rot1) && !SolidBlockList.isSolid(rot5)) {
blockData = 2;
}
}
}
} else {
blockData = 5;
if (rot1 == CHEST_BLOCK) {
rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ - 1);
} else {
rot5 = blockStorage.getBlockAt(startX - 1, startY, startZ + 1);
}
if (rot1 == CHEST_BLOCK) {
rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ - 1);
} else {
rot6 = blockStorage.getBlockAt(startX + 1, startY, startZ + 1);
}
if (SolidBlockList.isSolid(rot4) || SolidBlockList.isSolid(rot6)) {
if (!SolidBlockList.isSolid(rot3) && !SolidBlockList.isSolid(rot5)) {
blockData = 4;
}
}
}
return blockData;
}
use of com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage.BlockStorage in project DirtMultiversion by DirtPowered.
the class WorldPackets method registerTranslators.
@Override
public void registerTranslators() {
// block change
addTranslator(0x35, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
if (blockStorage.getVersion() == getTo()) {
int x = data.read(Type.INT, 0);
byte y = data.read(Type.BYTE, 1);
int z = data.read(Type.INT, 2);
int chunkX = x >> 4;
int chunkZ = z >> 4;
short blockId = data.read(Type.SHORT, 3);
if (shouldCache(blockId)) {
blockStorage.setBlockAt(chunkX, chunkZ, x, y, z, blockId);
}
}
return data;
}
});
addTranslator(0x34, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
if (blockStorage.getVersion() == getTo()) {
int chunkX = data.read(Type.INT, 0);
int chunkZ = data.read(Type.INT, 1);
V1_2MultiBlockArray blocks = data.read(Type.V1_2MULTIBLOCK_ARRAY, 2);
DataInput dis = new DataInputStream(new ByteArrayInputStream(blocks.getData()));
for (int i = 0; i < blocks.getRecordCount(); i++) {
try {
short pos = dis.readShort();
int x = pos >> 12 & 15;
int y = pos & 255;
int z = pos >> 8 & 15;
int xPos = x + (chunkX << 4);
int zPos = z + (chunkZ << 4);
int blockId = dis.readShort() >> 4 & 4095;
if (shouldCache(blockId)) {
blockStorage.setBlockAt(chunkX, chunkZ, xPos, y, zPos, blockId);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
return data;
}
});
// chunk data
addTranslator(0x33, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
V1_2Chunk chunk = data.read(Type.V1_2_CHUNK, 0);
if (blockStorage.getVersion() == getTo()) {
List<ExtendedBlockStorage> parts = new ArrayList<>();
boolean skyLight = true;
if (session.getStorage().hasObject(DimensionTracker.class)) {
DimensionTracker tracker = session.getStorage().get(DimensionTracker.class);
skyLight = tracker.getDimension() == 0;
}
// create chunk storage
V1_2RChunkStorage storage = new V1_2RChunkStorage(skyLight, true, chunk.getChunkX(), chunk.getChunkZ());
storage.readChunk(chunk.isGroundUp(), chunk.getPrimaryBitmap(), chunk.getUncompressedData());
// cache for later use (r1.8 -> r1.7)
chunk.setStorage(storage);
ExtendedBlockStorage[] columns = storage.getColumnStorage();
for (int i = 0; i < columns.length; ++i) {
ExtendedBlockStorage e = columns[i];
boolean f = e != null && !columns[i].isEmpty();
if (e != null && (chunk.getPrimaryBitmap() & 1 << i) != 0 && (!chunk.isGroundUp() || f)) {
parts.add(e);
}
}
for (int i = 0; i < parts.size(); ++i) {
byte[] blockArray = parts.get(i).getBlockLSBArray();
for (int j = 0; j < blockArray.length; ++j) {
int x = j & 15;
int y = (j >> 8) + i * 16 & 127;
int z = j >> 4 & 15;
int blockId = blockArray[j] & 255;
if (shouldCache(blockId)) {
blockStorage.setBlockAt(chunk.getChunkX(), chunk.getChunkZ(), x, y, z, blockId);
}
}
}
}
return data;
}
});
}
Aggregations