use of org.dragonet.inventory.PEInventorySlot in project Dragonet-Legacy by DragonetMC.
the class WindowItemsPacket method encode.
@Override
public void encode() {
try {
setChannel(NetworkChannel.CHANNEL_PRIORITY);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PEBinaryWriter writer = new PEBinaryWriter(bos);
writer.writeByte((byte) (this.pid() & 0xFF));
writer.writeByte(this.windowID);
writer.writeShort((short) (this.slots.length & 0xFFFF));
for (PEInventorySlot slot : this.slots) {
PEInventorySlot.writeSlot(writer, slot);
}
if (windowID == PEWindowConstantID.PLAYER_INVENTORY && this.hotbar.length > 0) {
writer.writeShort((short) (this.hotbar.length & 0xFFFF));
for (int slot : this.hotbar) {
writer.writeInt(slot);
}
} else {
writer.writeShort((short) 0);
}
this.setData(bos.toByteArray());
} catch (IOException e) {
}
}
use of org.dragonet.inventory.PEInventorySlot in project Dragonet-Legacy by DragonetMC.
the class EntityEquipmentMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(EntityEquipmentMessage packet) {
if (this.getSession().getPlayer() == null) {
return null;
}
if (!(this.getSession().getPlayer().getWorld().getEntityManager().getEntity(packet.id) instanceof Player)) {
// Only process player's equipments for now.
return null;
}
PlayerEquipmentPacket pkEquipment = new PlayerEquipmentPacket();
pkEquipment.eid = packet.id;
pkEquipment.slot = -1;
pkEquipment.selectedSlot = packet.slot;
if (packet.stack != null) {
pkEquipment.item = new PEInventorySlot((short) (packet.stack.getTypeId() & 0xFFFF), (byte) (packet.stack.getAmount() & 0xFF), (short) (packet.stack.getDurability() & 0xFFFF));
} else {
pkEquipment.item = new PEInventorySlot();
}
return new PEPacket[] { pkEquipment };
}
use of org.dragonet.inventory.PEInventorySlot 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.inventory.PEInventorySlot in project Dragonet-Legacy by DragonetMC.
the class EntityMetadataMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(EntityMetadataMessage packet) {
if (!this.getTranslator().cachedEntityIDs.contains(packet.id)) {
// Not spawned yet, let's create them
if (this.getTranslator().cachedSpawnObjects.containsKey(packet.id)) {
// Spawn it :)
SpawnObjectMessage msgObj = this.getTranslator().cachedSpawnObjects.get(packet.id);
switch(msgObj.type) {
case // Dropped Item
2:
AddItemEntityPacket pkAddItemEntity = new AddItemEntityPacket();
pkAddItemEntity.eid = msgObj.id;
pkAddItemEntity.item = new PEInventorySlot((short) (((ItemStack) packet.entries.get(0).value).getTypeId() & 0xFFFF), (byte) (((ItemStack) packet.entries.get(0).value).getAmount() & 0xFF), (short) (((ItemStack) packet.entries.get(0).value).getDurability() & 0xFFFF));
pkAddItemEntity.x = (float) msgObj.velX / 32;
pkAddItemEntity.y = (float) msgObj.velY / 32;
pkAddItemEntity.z = (float) msgObj.velZ / 32;
return new PEPacket[] { pkAddItemEntity };
}
// Remove it
this.getTranslator().cachedSpawnObjects.remove(packet.id);
} else {
return null;
}
}
return null;
}
use of org.dragonet.inventory.PEInventorySlot in project Dragonet-Legacy by DragonetMC.
the class UseItemPacketTranslator method handleSpecific.
@Override
public Message[] handleSpecific(UseItemPacket packet) {
UseItemPacket pkUseItem = (UseItemPacket) packet;
System.out.println("FACE=" + (pkUseItem.face & 0xFF) + ", ITEM=" + packet.item);
if (pkUseItem.face == 0xFF) {
// Air touch
// Left click air
PlayerSwingArmMessage msg = new PlayerSwingArmMessage();
return new Message[] { msg };
}
if (!(pkUseItem.face >= 0 && pkUseItem.face < 6)) {
return null;
}
// Check the slot
ItemStack test_holding = this.getSession().getPlayer().getInventory().getItemInHand();
if (packet.item.id != this.getTranslator().getItemTranslator().translateToPE(test_holding.getTypeId()) || packet.item.meta != test_holding.getDurability()) {
// Not same, resend slot
PlayerEquipmentPacket pkRet = new PlayerEquipmentPacket();
pkRet.eid = this.getSession().getPlayer().getEntityId();
pkRet.item = new PEInventorySlot((short) 0, (byte) 0, (short) 0);
pkRet.item.id = (short) (this.getTranslator().getItemTranslator().translateToPE(test_holding.getTypeId()) & 0xFFFF);
pkRet.item.count = (byte) (test_holding.getAmount() & 0xFF);
pkRet.item.meta = test_holding.getDurability();
pkRet.selectedSlot = this.getSession().getPlayer().getInventory().getHeldItemSlot();
// Resend block
UpdateBlockPacket pkUpdateBlock = new UpdateBlockPacket();
UpdateBlockPacket.UpdateBlockRecord blockRec = new UpdateBlockPacket.UpdateBlockRecord();
blockRec.x = packet.x;
blockRec.z = packet.z;
blockRec.y = (byte) (packet.y & 0xFF);
blockRec.block = (byte) (this.getSession().getPlayer().getWorld().getBlockAt(pkUseItem.x, pkUseItem.y, pkUseItem.z).getTypeId() & 0xFF);
blockRec.meta = (byte) (this.getSession().getPlayer().getWorld().getBlockAt(pkUseItem.x, pkUseItem.y, pkUseItem.z).getData() & 0xFF);
pkUpdateBlock.records = new UpdateBlockPacket.UpdateBlockRecord[] { blockRec };
getSession().send(pkRet);
getSession().send(pkUpdateBlock);
return null;
}
// Copied from Glowstone class BlockPlacementHandler
new BlockPlacementHandler().handle(getSession(), new BlockPlacementMessage(packet.x, packet.y, packet.z, packet.face, test_holding, 0, 0, 0));
return null;
}
Aggregations