@Override
@SuppressWarnings("unchecked")
public void processPacket(EntityPlayer player) {
IInventory inv = this.getTile(player.worldObj, IInventory.class);
if (inv instanceof ISidedInventory) inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);Slot result = null;
if(((List<Slot>)player.openContainer.inventorySlots).get(inventorySlot).slotNumber == inventorySlot) {
result = ((List<Slot>)player.openContainer.inventorySlots).get(inventorySlot);
}
if(result == null) {
for(Slot slotObject:(List<Slot>)player.openContainer.inventorySlots) {
if(slotObject.slotNumber == inventorySlot) {
result = slotObject;
break;
}
}
}
if(result == null) {
player.addChatComponentMessage(new ChatComponentTranslation("lp.chat.slotnotfound"));
}
int resultIndex = -1;
if(resultIndex == -1) {
ItemStack content = result.getStack();
if(content != null) {
for(int i=0;i<util.getSizeInventory();i++) {
if(content == util.getStackInSlot(i)) {
resultIndex = i;
break;
}
}
} else {
ItemStack dummyStack = new ItemStack(Blocks.stone, 0, 0);
NBTTagCompound nbt = new NBTTagCompound();
nbt.setBoolean("LPStackFinderBoolean", true); //Make it unique
dummyStack.setTagCompound(nbt);
result.putStack(dummyStack);
for(int i=0;i < util.getSizeInventory();i++) {
if(dummyStack == util.getStackInSlot(i)) {
resultIndex = i;
break;
}
}
if(resultIndex == -1) {
for(int i=0;i < util.getSizeInventory();i++) {
ItemStack stack = util.getStackInSlot(i);
if(stack == null) continue;
if(ItemIdentifier.get(stack).equals(ItemIdentifier.get(dummyStack)) && stack.stackSize == dummyStack.stackSize) {
resultIndex = i;
break;
}