Search in sources :

Example 6 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry in project DragonProxy by DragonetMC.

the class PCMultiBlockChangePacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerMultiBlockChangePacket packet) {
    UpdateBlockPacket[] packets = new UpdateBlockPacket[packet.getRecords().length];
    // int generalFlag = packet.getRecords().length > 64 ? UpdateBlockPacket.FLAG_ALL_PRIORITY : UpdateBlockPacket.FLAG_NEIGHBORS;
    for (int i = 0; i < packets.length; i++) {
        // update cache
        session.getChunkCache().update(packet.getRecords()[i].getPosition(), packet.getRecords()[i].getBlock());
        packets[i] = new UpdateBlockPacket();
        packets[i].blockPosition = new BlockPosition(packet.getRecords()[i].getPosition().getX(), packet.getRecords()[i].getPosition().getY(), packet.getRecords()[i].getPosition().getZ());
        ItemEntry entry = session.getChunkCache().translateBlock(packet.getRecords()[i].getPosition());
        packets[i].id = entry.getId();
        packets[i].flags = UpdateBlockPacket.FLAG_NEIGHBORS;
        packets[i].data = entry.getPEDamage();
    // Save glitchy items in cache
    // Position blockPosition = new Position(packets[i].blockPosition.x, packets[i].blockPosition.y, packets[i].blockPosition.z);
    }
    return packets;
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) UpdateBlockPacket(org.dragonet.protocol.packets.UpdateBlockPacket) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry)

Example 7 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry in project DragonProxy by DragonetMC.

the class ChunkCache method translateChunk.

public final ChunkData translateChunk(int columnX, int columnZ) {
    ChunkPos columnPos = new ChunkPos(columnX, columnZ);
    if (chunkCache.containsKey(columnPos)) {
        Column column = chunkCache.get(columnPos);
        ChunkData chunk = new ChunkData();
        chunk.sections = new Section[16];
        for (int i = 0; i < 16; i++) chunk.sections[i] = new Section();
        // Blocks
        for (int y = 0; y < 256; y++) {
            int cy = y >> 4;
            Chunk c = null;
            try {
                c = column.getChunks()[cy];
            } catch (Exception ex) {
                DragonProxy.getInstance().getLogger().info("Chunk " + columnX + ", " + cy + ", " + columnZ + " not exist !");
            }
            if (c == null || c.isEmpty())
                continue;
            BlockStorage blocks = c.getBlocks();
            for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) {
                BlockState block = blocks.get(x, y & 0xF, z);
                ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData());
                Section section = chunk.sections[cy];
                // Block id
                section.blockIds[index(x, y, z)] = (byte) (entry.getId() & 0xFF);
                // Data value
                int i = dataIndex(x, y, z);
                byte data = section.blockMetas[i];
                int newValue = entry.getPEDamage().byteValue();
                if ((y & 1) == 0)
                    data = (byte) ((data & 0xf0) | (newValue & 0x0f));
                else
                    data = (byte) (((newValue & 0x0f) << 4) | (data & 0x0f));
                section.blockMetas[i] = data;
            }
        }
        // Blocks entities
        try {
            List<CompoundTag> blockEntities = new ArrayList<>();
            for (int i = 0; i < column.getTileEntities().length; i++) {
                CompoundTag peTag = ItemBlockTranslator.translateBlockEntityToPE(column.getTileEntities()[i]);
                if (// filter non handled blocks entities
                peTag != null)
                    blockEntities.add(peTag);
            // else // debug
            // DragonProxy.getInstance().getLogger().debug("NBT null for " + pc.getTileEntities()[i].toString());
            }
            chunk.blockEntities = NBTIO.write(blockEntities, ByteOrder.LITTLE_ENDIAN, true);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        chunk.encode();
        return chunk;
    }
    // System.out.println("Chunk " + columnX + ", " + columnZ + " not in cache !!!!!!!!!!!!!");
    return null;
}
Also used : ChunkData(org.dragonet.protocol.type.chunk.ChunkData) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Chunk(com.github.steveice10.mc.protocol.data.game.chunk.Chunk) Section(org.dragonet.protocol.type.chunk.Section) IOException(java.io.IOException) BlockStorage(com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage) BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState) Column(com.github.steveice10.mc.protocol.data.game.chunk.Column) ChunkPos(org.dragonet.common.maths.ChunkPos) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry) CompoundTag(org.dragonet.common.data.nbt.tag.CompoundTag)

Example 8 with ItemEntry

use of org.dragonet.common.data.itemsblocks.ItemEntry in project DragonProxy by DragonetMC.

the class PCBlockChangePacketTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerBlockChangePacket packet) {
    // update cache
    session.getChunkCache().update(packet.getRecord().getPosition(), packet.getRecord().getBlock());
    // Save glitchy items in cache
    // Position blockPosition = new Position(pk.blockPosition.x, pk.blockPosition.y, pk.blockPosition.z);
    // session.getBlockCache().checkBlock(entry.getId(), entry.getPEDamage(), blockPosition);
    ItemEntry entry = session.getChunkCache().translateBlock(packet.getRecord().getPosition());
    if (entry != null) {
        UpdateBlockPacket pk = new UpdateBlockPacket();
        pk.flags = UpdateBlockPacket.FLAG_NEIGHBORS;
        pk.data = entry.getPEDamage();
        pk.id = entry.getId();
        pk.blockPosition = new BlockPosition(packet.getRecord().getPosition());
        session.putCachePacket(pk);
    }
    return null;
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry) UpdateBlockPacket(org.dragonet.protocol.packets.UpdateBlockPacket)

Aggregations

ItemEntry (org.dragonet.common.data.itemsblocks.ItemEntry)8 BlockPosition (org.dragonet.common.maths.BlockPosition)3 UpdateBlockPacket (org.dragonet.protocol.packets.UpdateBlockPacket)2 BlockStorage (com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage)1 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)1 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)1 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)1 ClientPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket)1 ClientVehicleMovePacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Block (org.dragonet.common.data.blocks.Block)1 Slot (org.dragonet.common.data.inventory.Slot)1 CompoundTag (org.dragonet.common.data.nbt.tag.CompoundTag)1 ChunkPos (org.dragonet.common.maths.ChunkPos)1 ChunkData (org.dragonet.protocol.type.chunk.ChunkData)1 Section (org.dragonet.protocol.type.chunk.Section)1 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)1