use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.
the class RelativeEntityPositionMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(RelativeEntityPositionMessage packet) {
Entity entity = this.getSession().getPlayer().getWorld().getEntityManager().getEntity(packet.id);
if (entity == null) {
return null;
}
if (entity instanceof GlowPlayer) {
boolean isTeleport = (packet.deltaX ^ 2 + packet.deltaY ^ 2 + packet.deltaZ ^ 2) > 4;
MovePlayerPacket pkMovePlayer = new MovePlayerPacket(packet.id, (float) entity.getLocation().getX(), (float) entity.getLocation().getY(), (float) entity.getLocation().getZ(), entity.getLocation().getYaw(), entity.getLocation().getPitch(), entity.getLocation().getYaw(), isTeleport);
return new PEPacket[] { pkMovePlayer };
} else {
MoveEntitiesPacket.MoveEntityData data = new MoveEntitiesPacket.MoveEntityData();
data.eid = packet.id;
data.x = (float) entity.getLocation().getX();
data.y = (float) entity.getLocation().getY();
data.z = (float) entity.getLocation().getZ();
data.yaw = (float) entity.getLocation().getYaw();
data.pitch = (float) entity.getLocation().getPitch();
MoveEntitiesPacket pk = new MoveEntitiesPacket(new MoveEntitiesPacket.MoveEntityData[] { data });
return new PEPacket[] { pk };
}
}
use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.
the class RelativeEntityPositionRotationMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(RelativeEntityPositionRotationMessage packet) {
Entity entity = this.getSession().getPlayer().getWorld().getEntityManager().getEntity(packet.id);
if (entity == null) {
return null;
}
if (entity instanceof GlowPlayer) {
boolean isTeleport = (packet.deltaX ^ 2 + packet.deltaY ^ 2 + packet.deltaZ ^ 2) > 4;
MovePlayerPacket pkMovePlayer = new MovePlayerPacket(packet.id, (float) entity.getLocation().getX(), (float) entity.getLocation().getY(), (float) entity.getLocation().getZ(), (float) entity.getLocation().getYaw(), (float) entity.getLocation().getPitch(), (float) entity.getLocation().getYaw(), isTeleport);
return new PEPacket[] { pkMovePlayer };
} else {
MoveEntitiesPacket.MoveEntityData data = new MoveEntitiesPacket.MoveEntityData();
data.eid = packet.id;
data.x = (float) entity.getLocation().getX();
data.y = (float) entity.getLocation().getY();
data.z = (float) entity.getLocation().getZ();
data.yaw = (float) entity.getLocation().getYaw();
data.pitch = (float) entity.getLocation().getPitch();
MoveEntitiesPacket pk = new MoveEntitiesPacket(new MoveEntitiesPacket.MoveEntityData[] { data });
return new PEPacket[] { pk };
}
}
use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.
the class SetWindowContentsMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(SetWindowContentsMessage packet) {
if (packet.id == 0) {
//Inventory Items(Included hotbar)
WindowItemsPacket pkInventory = new WindowItemsPacket();
pkInventory.windowID = PEWindowConstantID.PLAYER_INVENTORY;
pkInventory.slots = new PEInventorySlot[InventoryType.SlotSize.PLAYER];
for (int i = 9; i <= 44; i++) {
if (packet.items[i] != null) {
pkInventory.slots[i - 9] = new PEInventorySlot((short) (packet.items[i].getTypeId() & 0xFFFF), (byte) (packet.items[i].getAmount() & 0xFF), packet.items[i].getDurability());
} else {
pkInventory.slots[i - 9] = new PEInventorySlot();
}
}
pkInventory.hotbar = new int[9];
for (int i = 36; i <= 44; i++) {
pkInventory.hotbar[i - 36] = i - 9;
}
//Armor
WindowItemsPacket pkArmorInv = new WindowItemsPacket();
pkArmorInv.windowID = PEWindowConstantID.PLAYER_ARMOR;
pkArmorInv.slots = new PEInventorySlot[4];
for (int i = 5; i <= 8; i++) {
if (packet.items[i] != null) {
pkArmorInv.slots[i - 5] = new PEInventorySlot((short) (packet.items[i].getTypeId() & 0xFFFF), (byte) (packet.items[i].getAmount() & 0xFF), packet.items[i].getDurability());
} else {
pkArmorInv.slots[i - 5] = new PEInventorySlot();
}
}
return new PEPacket[] { pkInventory, pkArmorInv };
}
//TODO: Implement other types of inventory
//switch(this.getSession().getPlayer().)
System.out.println("Updating window content for " + packet.id + ", which has " + packet.items.length + " slots. ");
return null;
}
use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.
the class StateChangeMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(StateChangeMessage packet) {
if (packet.reason == StateChangeMessage.Reason.GAMEMODE.ordinal()) {
if (this.getSession().getPlayer() == null) {
return null;
}
StartGamePacket pkStartGame = new StartGamePacket();
pkStartGame.eid = this.getSession().getPlayer().getEntityId();
pkStartGame.gamemode = ((int) packet.value) & 0x1;
pkStartGame.seed = 0;
pkStartGame.generator = 1;
pkStartGame.spawnX = this.getSession().getPlayer().getWorld().getSpawnLocation().getBlockX();
pkStartGame.spawnY = this.getSession().getPlayer().getWorld().getSpawnLocation().getBlockY();
pkStartGame.spawnZ = this.getSession().getPlayer().getWorld().getSpawnLocation().getBlockZ();
pkStartGame.x = (float) this.getSession().getPlayer().getLocation().getX();
pkStartGame.y = (float) this.getSession().getPlayer().getLocation().getY();
pkStartGame.z = (float) this.getSession().getPlayer().getLocation().getZ();
return new PEPacket[] { pkStartGame };
}
return null;
}
use of org.dragonet.net.packet.minecraft.PEPacket in project Dragonet-Legacy by DragonetMC.
the class CloseWindowMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(CloseWindowMessage packet) {
if (packet.id != 0) {
this.getTranslator().cachedWindowType[packet.id & 0xFF] = -1;
}
WindowClosePacket pkCloseWindow = new WindowClosePacket();
pkCloseWindow.windowID = (byte) (packet.id & 0xFF);
getSession().getOpenedWindows().remove(packet.id);
return new PEPacket[] { pkCloseWindow };
}
Aggregations