use of com.github.steveice10.packetlib.Session in project DragonProxy by DragonetMC.
the class PingThread method setClient.
private void setClient() {
this.client = new Client(DragonProxy.getInstance().getConfig().remote_server_addr, DragonProxy.getInstance().getConfig().remote_server_port, new MinecraftProtocol(SubProtocol.STATUS), new TcpSessionFactory());
this.client.getSession().setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> {
this.info = info;
this.client.getSession().disconnect(null);
});
}
use of com.github.steveice10.packetlib.Session 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.Session 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.Session 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.Session 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