Search in sources :

Example 1 with Location

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

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

the class MoveTask method moveAlong.

private void moveAlong(final Location start, ArrayList<Tile> tiles) {
    Timer timer = new Timer();
    final Iterator<Tile> itr = tiles.iterator();
    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            if (itr.hasNext()) {
                Tile t = itr.next();
                Location loc = t.getLocation(start);
                // c.gui.addText("Position is: " + loc.getX() + ", " + loc.getY() + ", " + loc.getZ());
                // c.chat.sendMessage("Trying to move to: " + loc);
                calcMovement(new Location(loc.getBlockX() + 0.5, loc.getBlockY(), loc.getBlockZ() + 0.5));
            /* if(next != null){
               Location loc = next.getLocation(start);
               next = itr.next();
               Location locs = next.getLocation(start);
               double newYaw = 0, newPitch = 0;
               double xDiff = locs.getX() - c.location.getX();
			   double yDiff = locs.getY() - (c.location.getY() - 1);
			   double zDiff = locs.getZ() - c.location.getZ();
			   double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
			   double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
			   newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
			   newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
			   if(zDiff < 0.0) {
				 newYaw = newYaw + Math.abs(180 - newYaw) * 2;
			   }
			   c.yaw = (float) newYaw;
			   c.pitch = (float) newPitch;
			   if(!itr.hasNext()){
				   next = null;
			   }
               calcMovement(new Location(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
              }else{
               Tile t = itr.next();
               next = itr.next();
               Location locs = next.getLocation(start);
               double newYaw = 0, newPitch = 0;
               double xDiff = locs.getX() - c.location.getX();
			   double yDiff = locs.getY() - (c.location.getY() - 1);
			   double zDiff = locs.getZ() - c.location.getZ();
			   double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
			   double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
			   newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI;
			   newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90;
			   if(zDiff < 0.0) {
				 newYaw = newYaw + Math.abs(180 - newYaw) * 2;
			   }
               Location loc = t.getLocation(start);
               calcMovement(new Location(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
              }*/
            } else {
                this.cancel();
            }
        }
    };
    timer.scheduleAtFixedRate(task, 0, 100);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Tile(com.adamki11s.pathing.Tile) Location(me.xjcyan1de.cyanbot.world.Location)

Example 3 with Location

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

Example 4 with Location

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

the class CommandWhere method execute.

@Override
public void execute(CommandEvent event) {
    final Bot bot = event.getBot();
    final Entity entity = event.has(0, "я") ? bot.getWorld().getPlayer(event.getSender()) : bot.getWorld().getPlayer(event.arg(0));
    if (entity != null) {
        Schedule.cancel(timerTask);
        final Location loc = bot.getLoc();
        timerTask = Schedule.timer(new TimerCount(() -> {
            final float pitch = loc.getPitch();
            final float yaw = loc.getYaw();
            loc.setDir(entity.getX() - loc.getX(), entity.getY() - loc.getY(), entity.getZ() - loc.getZ());
            loc.setYaw(smoothly(loc.getYaw(), yaw));
            loc.setPitch(smoothly(loc.getPitch(), pitch));
            System.out.println(loc.getYaw() + " " + loc.getPitch());
        }, 100) {

            @Override
            public boolean cancel() {
                timerTask = null;
                bot.sendMessage("Та вижу я!");
                return super.cancel();
            }
        }, 50, 50);
    }
}
Also used : Entity(me.xjcyan1de.cyanbot.world.Entity) Bot(me.xjcyan1de.cyanbot.Bot) TimerCount(me.xjcyan1de.cyanbot.utils.schedule.TimerCount) Location(me.xjcyan1de.cyanbot.world.Location)

Example 5 with Location

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

the class MoveTask method goToLocation.

public void goToLocation(int x, int y, int z) {
    Location l = bot.getLoc().clone().add(0, -1, 0);
    Location loc = new Location(x, y - 1, z);
    runPathing(l, loc, 100);
}
Also used : Location(me.xjcyan1de.cyanbot.world.Location)

Aggregations

Location (me.xjcyan1de.cyanbot.world.Location)5 Block (me.xjcyan1de.cyanbot.world.Block)2 Tile (com.adamki11s.pathing.Tile)1 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 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Bot (me.xjcyan1de.cyanbot.Bot)1 TimerCount (me.xjcyan1de.cyanbot.utils.schedule.TimerCount)1 Entity (me.xjcyan1de.cyanbot.world.Entity)1