use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.
the class PCUpdateTileEntityPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerUpdateTileEntityPacket packet) {
BlockEntityDataPacket data = new BlockEntityDataPacket();
data.blockPosition = new BlockPosition(packet.getPosition());
data.tag = ItemBlockTranslator.translateBlockEntityToPE(packet.getNBT());
return new PEPacket[] { data };
}
use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.
the class PEMovePlayerPacketTranslator method translate.
public Packet[] translate(UpstreamSession session, MovePlayerPacket packet) {
CachedEntity entity = session.getEntityCache().getClientEntity();
if (entity.riding != 0 && packet.ridingRuntimeId != 0) {
// Riding case
ClientVehicleMovePacket pk = new ClientVehicleMovePacket(packet.position.x, packet.position.y - EntityType.PLAYER.getOffset(), packet.position.z, packet.yaw, packet.pitch);
session.getDownstream().send(pk);
} else {
// not riding
ClientPlayerPositionRotationPacket pk = new ClientPlayerPositionRotationPacket(packet.onGround, packet.position.x, // To simplify the movements
ceilToHalf(packet.position.y - EntityType.PLAYER.getOffset()), packet.position.z, packet.yaw, packet.pitch);
// Special blocks handling
boolean isColliding = false;
BlockPosition blockPos = new BlockPosition(NukkitMath.floorDouble(packet.position.x), NukkitMath.floorDouble(packet.position.y), NukkitMath.floorDouble(packet.position.z));
// System.out.println("block " + blockPos.toString());
try {
ItemEntry PEBlock = session.getChunkCache().translateBlock(blockPos.asPosition());
if (PEBlock != null) {
Block b = Block.get(PEBlock.getId(), PEBlock.getPEDamage(), blockPos);
if (b != null && b.collidesWithBB(session.getEntityCache().getClientEntity().boundingBox.clone())) {
DragonProxy.getInstance().getLogger().info("Player position : " + entity.x + ", " + entity.y + ", " + entity.z + " collide with " + b.getClass().getSimpleName() + " on " + blockPos.toString());
isColliding = true;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
entity.absoluteMove(pk.getX(), pk.getY(), pk.getZ(), (float) pk.getYaw(), (float) pk.getPitch());
if (!isColliding) {
session.getDownstream().send(pk);
session.getChunkCache().sendOrderedChunks();
}
}
return null;
}
use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.
the class ChestWindowTranslator method open.
public boolean open(UpstreamSession session, CachedWindow window) {
BlockPosition pos = new BlockPosition((int) session.getEntityCache().getClientEntity().x, (int) session.getEntityCache().getClientEntity().y - 4, (int) session.getEntityCache().getClientEntity().z);
ContainerOpenPacket pk = new ContainerOpenPacket();
pk.windowId = window.windowId;
pk.type = 0;
pk.position = pos;
session.putCachePacket(pk);
// System.out.println("ChestWindowTranslator.open " + window.windowId);
return true;
}
use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.
the class PCMultiBlockChangePacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerMultiBlockChangePacket packet) {
UpdateBlockPacket[] packets = new UpdateBlockPacket[packet.getRecords().length];
// int generalFlag = packet.getRecords().length > 64 ? UpdateBlockPacket.FLAG_ALL_PRIORITY : UpdateBlockPacket.FLAG_NEIGHBORS;
for (int i = 0; i < packets.length; i++) {
// update cache
session.getChunkCache().update(packet.getRecords()[i].getPosition(), packet.getRecords()[i].getBlock());
packets[i] = new UpdateBlockPacket();
packets[i].blockPosition = new BlockPosition(packet.getRecords()[i].getPosition().getX(), packet.getRecords()[i].getPosition().getY(), packet.getRecords()[i].getPosition().getZ());
ItemEntry entry = session.getChunkCache().translateBlock(packet.getRecords()[i].getPosition());
packets[i].id = entry.getId();
packets[i].flags = UpdateBlockPacket.FLAG_NEIGHBORS;
packets[i].data = entry.getPEDamage();
// Save glitchy items in cache
// Position blockPosition = new Position(packets[i].blockPosition.x, packets[i].blockPosition.y, packets[i].blockPosition.z);
}
return packets;
}
use of org.dragonet.common.maths.BlockPosition in project DragonProxy by DragonetMC.
the class ExplodePacket method encodePayload.
@Override
public void encodePayload() {
putVector3F(this.position);
putFloat(this.radius);
putUnsignedVarInt(this.destroyedBlocks.size());
for (BlockPosition position : this.destroyedBlocks) putBlockPosition(position);
}
Aggregations