Search in sources :

Example 11 with Position

use of com.github.steveice10.mc.protocol.data.game.entity.metadata.Position in project DragonProxy by DragonetMC.

the class ChunkCache method translateBlock.

public final ItemEntry translateBlock(Position position) {
    ChunkPos columnPos = new ChunkPos(position.getX() >> 4, position.getZ() >> 4);
    if (chunkCache.containsKey(columnPos))
        try {
            Column column = chunkCache.get(columnPos);
            BlockPosition blockPos = columnPos.getBlockInChunk(position.getX(), position.getY(), position.getZ());
            Chunk chunk = column.getChunks()[position.getY() >> 4];
            if (chunk != null) {
                BlockState block = chunk.getBlocks().get(blockPos.x, blockPos.y, blockPos.z);
                return ItemBlockTranslator.translateToPE(block.getId(), block.getData());
            }
        } catch (java.lang.ArrayIndexOutOfBoundsException ex) {
            this.session.getProxy().getLogger().info("getBlock(" + position.toString() + ")) fail to get chunk " + (position.getX() >> 4) + "/" + (position.getY() >> 4) + "/" + (position.getZ() >> 4));
            ex.printStackTrace();
        }
    return null;
}
Also used : BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState) Column(com.github.steveice10.mc.protocol.data.game.chunk.Column) BlockPosition(org.dragonet.common.maths.BlockPosition) ChunkPos(org.dragonet.common.maths.ChunkPos) Chunk(com.github.steveice10.mc.protocol.data.game.chunk.Chunk)

Aggregations

BlockPosition (org.dragonet.common.maths.BlockPosition)7 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)5 Packet (com.github.steveice10.packetlib.packet.Packet)4 ChunkPos (org.dragonet.common.maths.ChunkPos)4 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)3 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)3 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)3 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)3 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)3 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)2 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)2 ClientPlayerUseItemPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket)2 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)2 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)2 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 EntityMetadata (com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata)1 InteractAction (com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction)1 BlockFace (com.github.steveice10.mc.protocol.data.game.world.block.BlockFace)1 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)1 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)1