use of com.github.dirtpowered.dirtmv.data.transformers.block.Block in project DirtMultiversion by DirtPowered.
the class ProtocolRelease28To23 method registerTranslators.
@Override
public void registerTranslators() {
// login
addTranslator(0x01, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x01, new TypeHolder[] { set(Type.INT, 23), data.read(1), set(Type.LONG, 0L), data.read(2), data.read(3), set(Type.BYTE, data.read(Type.INT, 4).byteValue()), data.read(5), data.read(6), data.read(7) });
}
});
// login
addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
storage.set(DimensionTracker.class, new DimensionTracker());
// biome data only for < b1.7 for now
if (session.getMain().getConfiguration().getServerVersion().getRegistryId() < 17) {
OldChunkData biomeData = new OldChunkData();
biomeData.initialize(data.read(Type.LONG, 2));
storage.set(OldChunkData.class, biomeData);
}
int dimension = data.read(Type.BYTE, 5).intValue();
DimensionTracker dimensionTracker = storage.get(DimensionTracker.class);
dimensionTracker.setDimension(dimension);
return PacketUtil.createPacket(0x01, new TypeHolder[] { data.read(0), data.read(1), data.read(3), data.read(4), set(Type.INT, dimension), data.read(6), data.read(7), data.read(8) });
}
});
// pre chunk
addTranslator(0x32, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
LoadedChunkTracker chunkTracker = session.getUserData().getProtocolStorage().get(LoadedChunkTracker.class);
int chunkX = data.read(Type.INT, 0);
int chunkZ = data.read(Type.INT, 1);
byte mode = data.read(Type.BYTE, 2);
if (mode == 0) {
chunkTracker.removeChunk(chunkX, chunkZ);
}
return data;
}
});
// chunk
addTranslator(0x33, PacketDirection.TO_CLIENT, new BetaToV1_2ChunkTranslator(blockDataTransformer));
// multi block change
addTranslator(0x34, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
LoadedChunkTracker chunkTracker = session.getUserData().getProtocolStorage().get(LoadedChunkTracker.class);
V1_3BMultiBlockArray blockArray = (V1_3BMultiBlockArray) data.read(2).getObject();
int chunkX = data.read(Type.INT, 0);
int chunkZ = data.read(Type.INT, 1);
int totalDataSize = 4 * blockArray.getSize();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(totalDataSize);
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
V1_2MultiBlockArray newFormat = null;
try {
for (int i = 0; i < blockArray.getSize(); ++i) {
short coordinate = blockArray.getCoordsArray()[i];
int blockId = blockArray.getTypesArray()[i] & 255;
int blockData = blockArray.getMetadataArray()[i];
Block replacement = blockDataTransformer.replaceBlock(blockId, blockData);
dataOutputStream.writeShort(coordinate);
dataOutputStream.writeShort((short) ((replacement.getBlockId() & 4095) << 4 | replacement.getBlockData() & 15));
}
byte[] b = byteArrayOutputStream.toByteArray();
newFormat = new V1_2MultiBlockArray(blockArray.getSize(), b.length, b);
dataOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
if (!chunkTracker.isChunkLoaded(chunkX, chunkZ)) {
return cancel();
}
return PacketUtil.createPacket(0x34, new TypeHolder[] { data.read(0), data.read(1), set(Type.V1_2MULTIBLOCK_ARRAY, newFormat) });
}
});
// block change
addTranslator(0x35, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
LoadedChunkTracker chunkTracker = session.getUserData().getProtocolStorage().get(LoadedChunkTracker.class);
int chunkX = data.read(Type.INT, 0) >> 4;
int chunkZ = data.read(Type.INT, 2) >> 4;
byte blockId = data.read(Type.BYTE, 3);
byte blockData = data.read(Type.BYTE, 4);
Block replacement = blockDataTransformer.replaceBlock(blockId, blockData);
if (!chunkTracker.isChunkLoaded(chunkX, chunkZ)) {
return cancel();
}
return PacketUtil.createPacket(0x35, new TypeHolder[] { data.read(0), data.read(1), data.read(2), set(Type.BYTE, (byte) replacement.getBlockId()), set(Type.BYTE, (byte) replacement.getBlockData()) });
}
});
// mob spawn
addTranslator(0x18, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x18, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5), data.read(6), // head yaw
set(Type.BYTE, (byte) 0), data.read(7) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x09, new TypeHolder[] { set(Type.INT, (int) data.read(0).getObject()), data.read(1), data.read(2), data.read(3), // seed
set(Type.LONG, 0L), data.read(4) });
}
});
// respawn
addTranslator(0x09, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
int dimension = data.read(Type.BYTE, 0).intValue();
DimensionTracker dimensionTracker = storage.get(DimensionTracker.class);
dimensionTracker.setDimension(dimension);
return PacketUtil.createPacket(0x09, new TypeHolder[] { set(Type.INT, dimension), data.read(1), data.read(2), data.read(3), data.read(5) });
}
});
// entity relative move look
addTranslator(0x21, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
PacketData rotationPacket = PacketUtil.createPacket(0x23, new TypeHolder[] { // entityId
data.read(0), // yaw
data.read(4) });
session.sendPacket(rotationPacket, PacketDirection.TO_CLIENT, getFrom());
return data;
}
});
// entity look
addTranslator(0x20, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
PacketData rotationPacket = PacketUtil.createPacket(0x23, new TypeHolder[] { data.read(0), data.read(1) });
session.sendPacket(rotationPacket, PacketDirection.TO_CLIENT, getFrom());
return data;
}
});
// door change
addTranslator(0x3D, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int effectId = data.read(Type.INT, 0);
int effectData = data.read(Type.INT, 4);
if (effectId == 2001) {
int blockId = effectData & 255;
int blockData = effectData >> 8 & 255;
effectData = blockId + (blockData << 12);
}
return PacketUtil.createPacket(0x3D, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), set(Type.INT, effectData) });
}
});
// creative item get
addTranslator(0x6B, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_0R_ITEM, 1);
boolean notNull = item != null;
if (notNull && !creativeTab.exists(item.getItemId())) {
// replace all unknown items to stone
item.setItemId(1);
item.setData(0);
}
return PacketUtil.createPacket(0x6B, new TypeHolder[] { data.read(0), set(Type.V1_0R_ITEM, item) });
}
});
}
use of com.github.dirtpowered.dirtmv.data.transformers.block.Block in project DirtMultiversion by DirtPowered.
the class BetaToV1_2ChunkTranslator method getUpdatedBlockList.
private List<WorldBlock> getUpdatedBlockList(int x, int y, int z, int xSize, int ySize, int zSize, byte[] packetData, boolean replaceChests) {
List<WorldBlock> worldBlocks = new ArrayList<>();
int chunkX = x >> 4;
int chunkZ = z >> 4;
int startPosition = x + xSize - 1 >> 4;
int endPosition = z + zSize - 1 >> 4;
int offset = 0;
int startY = Math.max(y, 0);
int endY = Math.min(y + ySize, 128);
for (int i = chunkX; i <= startPosition; ++i) {
int startX = Math.max(x - i * 16, 0);
int newXSize = Math.min(x + xSize - i * 16, 16);
for (int j = chunkZ; j <= endPosition; ++j) {
int startZ = Math.max(z - j * 16, 0);
int newZSize = Math.min(z + zSize - j * 16, 16);
V1_3BChunkStorage oldChunk = new V1_3BChunkStorage(i, j);
offset = oldChunk.setChunkData(packetData, startX, startY, startZ, newXSize, endY, newZSize, offset, false);
for (int posX = startX; posX < newXSize; posX++) {
for (int posY = startY; posY < endY; posY++) {
for (int posZ = startZ; posZ < newZSize; posZ++) {
int oldBlockId = oldChunk.getBlockId(posX, posY, posZ);
int oldBlockData = oldChunk.getBlockData(posX, posY, posZ);
if (oldBlockId == 54 && replaceChests) {
oldBlockId = 130;
oldBlockData = 2;
}
Block b = blockDataTransformer.replaceBlock(oldBlockId, oldBlockData);
worldBlocks.add(new WorldBlock(x + (posX - startX), posY, z + (posZ - startZ), b.getBlockId(), b.getBlockData()));
}
}
}
}
}
return worldBlocks;
}
use of com.github.dirtpowered.dirtmv.data.transformers.block.Block in project DirtMultiversion by DirtPowered.
the class BetaToV1_2ChunkTranslator method translate.
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
LoadedChunkTracker chunkTracker = storage.get(LoadedChunkTracker.class);
DimensionTracker dimensionTracker = storage.get(DimensionTracker.class);
boolean hasSkylight = dimensionTracker.getDimension() == 0;
V1_3BChunk oldChunk = (V1_3BChunk) data.read(0).getObject();
boolean groundUp = true;
if (oldChunk.getXSize() * oldChunk.getYSize() * oldChunk.getZSize() != 32768) {
groundUp = false;
}
int chunkX = oldChunk.getX() >> 4;
int chunkZ = oldChunk.getZ() >> 4;
if (groundUp) {
V1_3BChunkStorage oldChunkStorage = new V1_3BChunkStorage(chunkX, chunkZ);
V1_2RChunkStorage newChunkStorage = new V1_2RChunkStorage(hasSkylight, true, chunkX, chunkZ);
oldChunkStorage.setChunkData(oldChunk.getChunk(), oldChunk.getX(), oldChunk.getY(), oldChunk.getZ(), oldChunk.getXSize(), oldChunk.getYSize(), oldChunk.getZSize(), 0, true);
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 128; y++) {
for (int z = 0; z < 16; z++) {
int oldBlockId = oldChunkStorage.getBlockId(x, y, z);
int oldBlockData = oldChunkStorage.getBlockData(x, y, z);
Block replacement = blockDataTransformer.replaceBlock(oldBlockId, oldBlockData);
newChunkStorage.setBlockId(x, y, z, replacement.getBlockId());
newChunkStorage.setBlockMetadata(x, y, z, replacement.getBlockData());
newChunkStorage.setBlockLight(x, y, z, oldChunkStorage.getBlockLight(x, y, z));
if (hasSkylight) {
newChunkStorage.setSkyLight(x, y, z, oldChunkStorage.getSkyLight(x, y, z));
}
}
}
}
byte[] biomes = new byte[256];
if (storage.hasObject(OldChunkData.class)) {
OldChunkData biomeData = storage.get(OldChunkData.class);
biomes = biomeData.getBiomeDataAt(chunkX, chunkZ, !hasSkylight);
} else {
// forest
Arrays.fill(biomes, (byte) 0x04);
}
newChunkStorage.setBiomeData(biomes);
byte[] compressedData = newChunkStorage.getCompressedData(true, 0xff);
session.sendPacket(PacketUtil.createPacket(0x33, new TypeHolder[] { new TypeHolder<>(Type.V1_2_CHUNK, new V1_2Chunk(chunkX, chunkZ, true, (short) newChunkStorage.getPrimaryBitmap(), (short) 0, newChunkStorage.getCompressedSize(), compressedData, new byte[0], newChunkStorage)) }), PacketDirection.TO_CLIENT, MinecraftVersion.R1_2_1);
chunkTracker.setChunkLoaded(chunkX, chunkZ);
return ServerProtocol.cancel();
} else {
if (!chunkTracker.isChunkLoaded(chunkX, chunkZ)) {
return ServerProtocol.cancel();
}
Configuration c = session.getMain().getConfiguration();
boolean replaceChests = session.getUserData().getClientVersion().getRegistryId() >= 39 && c.replaceChests();
List<WorldBlock> worldBlocks = getUpdatedBlockList(oldChunk.getX(), oldChunk.getY(), oldChunk.getZ(), oldChunk.getXSize(), oldChunk.getYSize(), oldChunk.getZSize(), oldChunk.getChunk(), replaceChests);
int records = worldBlocks.size();
if (worldBlocks.isEmpty()) {
return ServerProtocol.cancel();
}
List<List<WorldBlock>> slicedList = getSlicedData(worldBlocks);
if (records > MAX_SINGLE_BLOCK_UPDATE_PACKETS) {
for (List<WorldBlock> slicedData : slicedList) {
chunkX = slicedData.get(0).getX() >> 4;
chunkZ = slicedData.get(0).getZ() >> 4;
int totalDataSize = 4 * slicedData.size();
ByteArrayOutputStream baos = new ByteArrayOutputStream(totalDataSize);
DataOutputStream dos = new DataOutputStream(baos);
V1_2MultiBlockArray blockArray = null;
try {
for (WorldBlock record : slicedData) {
dos.writeShort((record.getX() - (chunkX << 4)) << 12 | (record.getZ() - (chunkZ << 4)) << 8 | record.getY());
dos.writeShort((record.getBlockId() & 4095) << 4 | record.getBlockData() & 15);
}
byte[] bytes = baos.toByteArray();
blockArray = new V1_2MultiBlockArray(slicedData.size(), bytes.length, bytes);
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
PacketData multiBlockChange = PacketUtil.createPacket(0x34, new TypeHolder[] { new TypeHolder<>(Type.INT, chunkX), new TypeHolder<>(Type.INT, chunkZ), new TypeHolder<>(Type.V1_2MULTIBLOCK_ARRAY, blockArray) });
session.sendPacket(multiBlockChange, PacketDirection.TO_CLIENT, MinecraftVersion.R1_2_1);
}
} else {
for (WorldBlock block : worldBlocks) {
PacketData blockUpdate = PacketUtil.createPacket(0x35, new TypeHolder[] { new TypeHolder<>(Type.INT, block.getX()), new TypeHolder<>(Type.BYTE, (byte) block.getY()), new TypeHolder<>(Type.INT, block.getZ()), new TypeHolder<>(Type.BYTE, (byte) block.getBlockId()), new TypeHolder<>(Type.BYTE, (byte) block.getBlockData()) });
session.sendPacket(blockUpdate, PacketDirection.TO_CLIENT, MinecraftVersion.R1_2_1);
}
}
}
return ServerProtocol.cancel();
}
use of com.github.dirtpowered.dirtmv.data.transformers.block.Block in project DirtMultiversion by DirtPowered.
the class ItemRemapper method registerReplacements.
@Override
public void registerReplacements() {
addItemReplacement(26, 0, new Block(355, 0, "Bed block"));
addItemReplacement(34, 0, new Block(33, 0, "Piston extension"));
addItemReplacement(36, 0, new Block(33, 0, "Piston moving piece"));
addItemReplacement(55, 0, new Block(331, 0, "Redstone wire"));
addItemReplacement(59, 0, new Block(295, 0, "Wheat crops"));
addItemReplacement(63, 0, new Block(323, 0, "Standing sign"));
addItemReplacement(64, 0, new Block(324, 0, "Oak door block"));
addItemReplacement(68, 0, new Block(323, 0, "Wall sign"));
addItemReplacement(71, 0, new Block(330, 0, "Iron door block"));
addItemReplacement(74, 0, new Block(73, 0, "Glowing redstone ore"));
addItemReplacement(75, 0, new Block(76, 0, "Restone torch off"));
addItemReplacement(83, 0, new Block(338, 0, "Sugar cane block"));
addItemReplacement(92, 0, new Block(354, 0, "Cake block"));
addItemReplacement(93, 0, new Block(356, 0, "Diode block off"));
addItemReplacement(94, 0, new Block(356, 0, "Diode block on"));
addItemReplacement(95, 0, new Block(146, 0, "Locked Chest"));
addItemReplacement(104, 0, new Block(361, 0, "Pumpkin stem"));
addItemReplacement(105, 0, new Block(362, 0, "Melon stem"));
addItemReplacement(115, 0, new Block(372, 0, "Nether warts"));
addItemReplacement(117, 0, new Block(379, 0, "Brewing stand"));
addItemReplacement(118, 0, new Block(380, 0, "Cauldron"));
addItemReplacement(124, 0, new Block(123, 0, "Restone lamp on"));
addItemReplacement(132, 0, new Block(287, 0, "Tripwire"));
addItemReplacement(140, 0, new Block(390, 0, "Flower pot"));
addItemReplacement(144, 0, new Block(397, 0, "Skull"));
addItemReplacement(149, 0, new Block(404, 0, "Redstone comparator off"));
addItemReplacement(150, 0, new Block(404, 0, "Redstone comparator on"));
}
use of com.github.dirtpowered.dirtmv.data.transformers.block.Block in project DirtMultiversion by DirtPowered.
the class ItemRemapper method registerReplacements.
@Override
public void registerReplacements() {
addItemReplacement(8, 0, new Block(326, 0, "Water"));
addItemReplacement(9, 0, new Block(326, 0, "Stationary Water"));
addItemReplacement(10, 0, new Block(327, 0, "Lava"));
addItemReplacement(11, 0, new Block(327, 0, "Stationary lava"));
addItemReplacement(43, 0, new Block(44, 0, "Double step"));
addItemReplacement(44, 2, new Block(126, 0, "Wooden slab"));
addItemReplacement(51, 0, new Block(385, 0, "Fire"));
addItemReplacement(90, 0, new Block(160, 10, "Nether portal"));
addItemReplacement(119, 0, new Block(399, 0, "End portal"));
addItemReplacement(125, 0, new Block(126, 0, "Wood double step"));
addItemReplacement(127, 0, new Block(351, 3, "Cocoa"));
addItemReplacement(141, 0, new Block(391, 0, "Carrots"));
addItemReplacement(142, 0, new Block(392, 0, "Potato"));
}
Aggregations