Search in sources :

Example 21 with BlockPosition

use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.

the class ChestWindowTranslator method prepare.

public boolean prepare(UpstreamSession session, CachedWindow window) {
    BlockPosition pos = new BlockPosition((int) session.getEntityCache().getClientEntity().x, (int) session.getEntityCache().getClientEntity().y - 4, (int) session.getEntityCache().getClientEntity().z);
    session.getDataCache().put(CacheKey.CURRENT_WINDOW_POSITION, pos);
    session.sendFakeBlock(pos.x, pos.y, pos.z, 54, 0);
    BlockEntityDataPacket blockEntityData = new BlockEntityDataPacket();
    blockEntityData.blockPosition = pos;
    blockEntityData.tag = ItemBlockTranslator.translateBlockEntityToPE(ItemBlockTranslator.newTileTag("minecraft:chest", pos.x, pos.y, pos.z));
    if (window.size - 36 > 27) {
        // DoubleChest
        blockEntityData.tag.putInt("pairx", pos.x + 1);
        blockEntityData.tag.putInt("pairz", pos.z);
    } else
        // SimpleChest
        session.sendPacket(blockEntityData);
    if (window.size - 36 > 27) {
        // DoubleChest
        BlockPosition pos2 = new BlockPosition(pos.x + 1, pos.y, pos.z);
        session.sendFakeBlock(pos2.x, pos2.y, pos2.z, 54, 0);
        BlockEntityDataPacket blockEntityData2 = new BlockEntityDataPacket();
        blockEntityData2.blockPosition = pos2;
        blockEntityData2.tag = ItemBlockTranslator.translateBlockEntityToPE(ItemBlockTranslator.newTileTag("minecraft:chest", pos2.x, pos2.y, pos2.z));
        blockEntityData2.tag.putInt("pairx", pos.x);
        blockEntityData2.tag.putInt("pairz", pos.z);
        session.sendPacket(blockEntityData2);
        session.sendPacket(blockEntityData);
        ArrayList<BlockPosition> posList = new ArrayList<>();
        posList.add(pos);
        posList.add(pos2);
        session.getDataCache().put(CacheKey.CURRENT_WINDOW_POSITION, posList);
    }
    // System.out.println("ChestWindowTranslator.prepare " + window.windowId);
    return true;
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) ArrayList(java.util.ArrayList)

Example 22 with BlockPosition

use of org.dragonet.common.maths.BlockPosition 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

BlockPosition (org.dragonet.common.maths.BlockPosition)22 Vector3F (org.dragonet.common.maths.Vector3F)5 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)5 ChunkPos (org.dragonet.common.maths.ChunkPos)4 PEPacket (org.dragonet.protocol.PEPacket)4 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)3 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)3 ItemEntry (org.dragonet.common.data.itemsblocks.ItemEntry)3 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)2 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)2 ArrayList (java.util.ArrayList)2 ByteArrayMeta (org.dragonet.common.data.entity.meta.type.ByteArrayMeta)2 SlotMeta (org.dragonet.common.data.entity.meta.type.SlotMeta)2 UpdateBlockPacket (org.dragonet.protocol.packets.UpdateBlockPacket)2 ChunkData (org.dragonet.protocol.type.chunk.ChunkData)2 Section (org.dragonet.protocol.type.chunk.Section)2 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 AuthenticationService (com.github.steveice10.mc.auth.service.AuthenticationService)1 MinecraftProtocol (com.github.steveice10.mc.protocol.MinecraftProtocol)1 EntityMetadata (com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata)1