use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.
the class PEPlayerActionPacketTranslator method translate.
public Packet[] translate(UpstreamSession session, PlayerActionPacket packet) {
if (packet.action == PlayerActionPacket.ACTION_RESPAWN) {
return new Packet[] { new ClientRequestPacket(ClientRequest.RESPAWN) };
}
if (packet.action == PlayerActionPacket.ACTION_START_SPRINT) {
ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SPRINTING);
return new Packet[] { stat };
}
if (packet.action == PlayerActionPacket.ACTION_STOP_SPRINT) {
ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SPRINTING);
return new Packet[] { stat };
}
if (packet.action == PlayerActionPacket.ACTION_START_GLIDE) {
ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
return new Packet[] { stat };
}
if (packet.action == PlayerActionPacket.ACTION_STOP_GLIDE) {
ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
return new Packet[] { stat };
}
if (packet.action == PlayerActionPacket.ACTION_START_SNEAK) {
ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SNEAKING);
return new Packet[] { stat };
}
if (packet.action == PlayerActionPacket.ACTION_STOP_SNEAK) {
ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SNEAKING);
return new Packet[] { stat };
}
if (packet.action == PlayerActionPacket.ACTION_STOP_SLEEPING) {
ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.LEAVE_BED);
return new Packet[] { stat };
}
if (packet.action == PlayerActionPacket.ACTION_DROP_ITEM) {
ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, new Position(0, 0, 0), BlockFace.UP);
return new Packet[] { act };
}
if (packet.action == PlayerActionPacket.ACTION_START_BREAK) {
ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.START_DIGGING, new Position(packet.position.x, packet.position.y, packet.position.z), MagicValues.key(BlockFace.class, packet.face));
session.getDataCache().put(CacheKey.BLOCK_BREAKING_POSITION, act.getPosition());
return new Packet[] { act };
}
if (session.getDataCache().containsKey(CacheKey.BLOCK_BREAKING_POSITION)) {
if (packet.action == PlayerActionPacket.ACTION_STOP_BREAK) {
ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.FINISH_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
return new Packet[] { act };
}
if (packet.action == PlayerActionPacket.ACTION_ABORT_BREAK) {
ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.CANCEL_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
return new Packet[] { act };
}
}
return null;
}
use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.
the class PCEntityEquipmentPacketTranslator method translate.
@Override
public PEPacket[] translate(UpstreamSession session, ServerEntityEquipmentPacket packet) {
CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
if (entity == null) {
if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) {
entity = session.getEntityCache().getClientEntity();
} else {
return null;
}
}
ItemStack items = packet.getItem();
boolean handModified = false;
switch(packet.getSlot()) {
case HELMET:
entity.helmet = ItemBlockTranslator.translateSlotToPE(items);
break;
case CHESTPLATE:
entity.chestplate = ItemBlockTranslator.translateSlotToPE(items);
break;
case LEGGINGS:
entity.leggings = ItemBlockTranslator.translateSlotToPE(items);
break;
case BOOTS:
entity.boots = ItemBlockTranslator.translateSlotToPE(items);
break;
case MAIN_HAND:
entity.mainHand = ItemBlockTranslator.translateSlotToPE(items);
case OFF_HAND:
handModified = true;
break;
}
entity.updateEquipment(session);
if (handModified) {
MobEquipmentPacket equipPacket = new MobEquipmentPacket();
equipPacket.rtid = entity.proxyEid;
equipPacket.item = entity.mainHand;
equipPacket.inventorySlot = 0;
equipPacket.hotbarSlot = 0;
equipPacket.windowId = 0;
session.sendPacket(equipPacket);
}
return null;
}
use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.
the class PCPlaySoundPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) {
try {
String soundName;
if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) {
BuiltinSound sound = (BuiltinSound) packet.getSound();
soundName = sound.name();
} else {
soundName = ((CustomSound) packet.getSound()).getName();
}
if (soundName == null) {
return null;
}
PlaySoundPacket pk = new PlaySoundPacket();
pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
pk.name = soundName;
pk.volume = packet.getVolume();
pk.pitch = packet.getPitch();
return new PEPacket[] { pk };
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of com.github.steveice10.packetlib.packet.Packet in project DragonProxy by DragonetMC.
the class PEBlockPickRequestPacketTranslator method translate.
@Override
public Packet[] translate(UpstreamSession session, BlockPickRequestPacket packet) {
ItemStack item = session.getChunkCache().getBlock(new Position(packet.x, packet.y, packet.z));
int selectedSlot = (int) session.getDataCache().getOrDefault(CacheKey.PLAYER_SELECTED_SLOT, 36);
ClientCreativeInventoryActionPacket backPacket = new ClientCreativeInventoryActionPacket(selectedSlot + 36, item);
// System.out.println("BlockPickRequestPacket " + DebugTools.getAllFields(packet));
// System.out.println("ItemStack " + DebugTools.getAllFields(item));
session.getChunkCache().getDebugGrid();
return new Packet[] { backPacket };
}
use of com.github.steveice10.packetlib.packet.Packet 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;
}
Aggregations