Search in sources :

Example 1 with Block

use of me.xjcyan1de.cyanbot.world.Block 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 Block

use of me.xjcyan1de.cyanbot.world.Block in project CyanBot by XjCyan1de.

the class CollisionHandler method onUpdate.

@Override
public void onUpdate() {
    // Get the first solid block under the bot, this could be very far away
    Block solid = bot.getSolidBlock();
    if (solid != null) {
        if (loc.getY() + speed.getY() < solid.getY() + 1) {
            speed.setY(0);
            loc.setY(solid.getY() + 1);
        }
    }
}
Also used : Block(me.xjcyan1de.cyanbot.world.Block)

Example 3 with Block

use of me.xjcyan1de.cyanbot.world.Block in project CyanBot by XjCyan1de.

the class AStar method isLocationWalkable.

private boolean isLocationWalkable(Location l) {
    Block b = world.getBlockAt(l);
    int i = b.getId();
    int d = 0;
    System.out.println("The block ID was: " + i);
    if (i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != d && (!canBlockBeWalkedThrough(i))) {
        // make sure the blocks above are air or can be walked through
        System.out.println("Location is: " + b.getX() + " " + b.getY() + " " + b.getZ());
        System.out.println("ID1: " + b.getRelative(0, 1, 0).getId() + " ID2: " + b.getRelative(0, 2, 0).getId());
        System.out.println("But here: " + canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getId()) + " and this is: " + (b.getRelative(0, 2, 0).getId() == 0));
        return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getId()) && canBlockBeWalkedThrough(b.getRelative(0, 2, 0).getId()));
    } else {
        return false;
    }
}
Also used : Block(me.xjcyan1de.cyanbot.world.Block)

Example 4 with Block

use of me.xjcyan1de.cyanbot.world.Block in project CyanBot by XjCyan1de.

the class AStar method isTileWalkable.

private boolean isTileWalkable(Tile t) {
    Location l = new Location((sx + t.getX()), (sy + t.getY()), (sz + t.getZ()));
    Block b = world.getBlockAt(l);
    int i = b.getId();
    // lava, fire, wheat and ladders cannot be walked on, and of course air
    // 85, 107 and 113 stops npcs climbing fences and fence gates
    int d = 0;
    if (i != 8 && i != 9 && i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != d && i != 85 && i != 107 && i != 113 && !canBlockBeWalkedThrough(i)) {
        /*if (b.getRelative(0, 1, 0).getId() == 107) {
                // fench gate check, if closed continue
                Gate g = new Gate(b.getRelative(0, 1, 0).getData());
                return (g.isOpen() ? (b.getRelative(0, 2, 0).getId() == 0) : false);//TODO support this
            }*/
        return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getId()) && canBlockBeWalkedThrough(b.getRelative(0, 2, 0).getId()));
    } else {
        return false;
    }
}
Also used : Block(me.xjcyan1de.cyanbot.world.Block) Location(me.xjcyan1de.cyanbot.world.Location)

Aggregations

Block (me.xjcyan1de.cyanbot.world.Block)4 Location (me.xjcyan1de.cyanbot.world.Location)2 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)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