Search in sources :

Example 1 with BlockState

use of com.github.steveice10.mc.protocol.data.game.world.block.BlockState in project CyanBot by XjCyan1de.

the class PacketWorldListener method packetReceived.

@Override
public void packetReceived(PacketReceivedEvent event) {
    try {
        Packet packetHandle = event.getPacket();
        if (packetHandle instanceof ServerJoinGamePacket) {
            ServerJoinGamePacket packet = (ServerJoinGamePacket) packetHandle;
            bot.setEntityId(packet.getEntityId());
        } else if (packetHandle instanceof ServerPlayerPositionRotationPacket) {
            ServerPlayerPositionRotationPacket packet = (ServerPlayerPositionRotationPacket) packetHandle;
            Location location = new Location(packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getPitch());
            bot.setLoc(location);
            // bot.sendMessage("Меня тпхнуло: "+location);
            // System.out.println(" \nТелепортируем : ["+location.getX()+" "+location.getY()+" "+location.getZ()+"]");
            bot.sendPacket(new ClientTeleportConfirmPacket(packet.getTeleportId()));
        // bot.groundHandler.move(location);
        } else if (packetHandle instanceof ServerChunkDataPacket) {
            ServerChunkDataPacket packet = (ServerChunkDataPacket) packetHandle;
            bot.getWorld().onLoadChunk(bot, packet.getColumn());
        } else if (packetHandle instanceof ServerUnloadChunkPacket) {
            ServerUnloadChunkPacket packet = (ServerUnloadChunkPacket) packetHandle;
            bot.getWorld().onUnloadChunk(bot, packet.getX(), packet.getZ());
        } else if (packetHandle instanceof ServerPlayerHealthPacket) {
            ServerPlayerHealthPacket packet = (ServerPlayerHealthPacket) packetHandle;
            if (packet.getHealth() == 0) {
                Schedule.later(() -> {
                    bot.sendPacket(new ClientRequestPacket(ClientRequest.RESPAWN));
                }, 500);
            }
        } else if (packetHandle instanceof ServerBlockChangePacket) {
            ServerBlockChangePacket packet = (ServerBlockChangePacket) packetHandle;
            BlockState blockState = packet.getRecord().getBlock();
            if (blockState != null) {
                Position position = packet.getRecord().getPosition();
                Block block = bot.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
                if (block != null) {
                    block.setIdAndData(blockState.getId(), blockState.getData());
                // System.out.println("Новый блок = " + block);
                } else {
                    System.out.println("Чё за хуйня у нас блок == Null" + position.getX() + " " + position.getY() + " " + position.getZ());
                }
            }
        } else {
        /*if (packetHandle instanceof ServerUpdateTimePacket ||
                        packetHandle instanceof ServerKeepAlivePacket ||
                        packetHandle instanceof ServerPlaySoundPacket ||
                        packetHandle instanceof ServerEntityEffectPacket

                        ) {
                } else {
                    //System.out.println(bot.getUsername()+" <- "+packetHandle);
                }*/
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) Packet(com.github.steveice10.packetlib.packet.Packet) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState) Block(me.xjcyan1de.cyanbot.world.Block) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) Location(me.xjcyan1de.cyanbot.world.Location)

Example 2 with BlockState

use of com.github.steveice10.mc.protocol.data.game.world.block.BlockState in project CyanBot by XjCyan1de.

the class Block method setIdAndData.

public void setIdAndData(int id, int data) {
    this.id = id;
    this.data = data;
    world.setBlockState(x, y, z, new BlockState(id, data));
}
Also used : BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState)

Example 3 with BlockState

use of com.github.steveice10.mc.protocol.data.game.world.block.BlockState in project CyanBot by XjCyan1de.

the class Block method setId.

public void setId(int id) {
    this.id = id;
    world.setBlockState(x, y, z, new BlockState(id, this.data));
}
Also used : BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState)

Example 4 with BlockState

use of com.github.steveice10.mc.protocol.data.game.world.block.BlockState in project DragonProxy by DragonetMC.

the class ChunkCache method update.

public void update(Position position, BlockState block) {
    ChunkPos columnPos = new ChunkPos(position.getX() >> 4, position.getZ() >> 4);
    // System.out.println("translateBlock Position " + position.toString());
    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)
                chunk.getBlocks().set(blockPos.x, blockPos.y, blockPos.z, block);
        } catch (java.lang.ArrayIndexOutOfBoundsException ex) {
            this.session.getProxy().getLogger().info("update(" + position.toString() + ", " + block.toString() + ")) fail to get chunk " + (position.getX() >> 4) + "/" + (position.getY() >> 4) + "/" + (position.getZ() >> 4));
            ex.printStackTrace();
        }
// enqueue block update
}
Also used : 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)

Example 5 with BlockState

use of com.github.steveice10.mc.protocol.data.game.world.block.BlockState in project DragonProxy by DragonetMC.

the class ChunkCache method getBlock.

public final ItemStack getBlock(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 new ItemStack(block.getId(), 1, block.getData());
            }
        } catch (java.lang.ArrayIndexOutOfBoundsException ex) {
            this.session.getProxy().getLogger().severe("(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) ItemStack(com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)

Aggregations

BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)7 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)4 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)4 ChunkPos (org.dragonet.common.maths.ChunkPos)4 BlockPosition (org.dragonet.common.maths.BlockPosition)3 BlockStorage (com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage)1 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)1 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)1 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)1 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)1 ServerPlayerHealthPacket (com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket)1 ServerPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket)1 Packet (com.github.steveice10.packetlib.packet.Packet)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Block (me.xjcyan1de.cyanbot.world.Block)1 Location (me.xjcyan1de.cyanbot.world.Location)1 ItemEntry (org.dragonet.common.data.itemsblocks.ItemEntry)1 CompoundTag (org.dragonet.common.data.nbt.tag.CompoundTag)1