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