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();
}
}
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);
}
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;
}
}
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);
}
}
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);
}
Aggregations