if (mc.thePlayer == null) {
return;
}
PacketSlotClick packet = new PacketSlotClick(slot, button,Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT));
SpoutClient.getInstance().getPacketManager().sendSpoutPacket(packet);
ItemStack stackOnCursor = new ItemStack(0);
if (mc.thePlayer.inventory.getItemStack() != null) {
net.minecraft.src.ItemStack mcStack = mc.thePlayer.inventory.getItemStack();
stackOnCursor = new ItemStack(mcStack.itemID, mcStack.stackSize, (short) mcStack.getItemDamage());
}
ItemStack stackInSlot = slot.getItem();
if ((stackOnCursor == null || stackOnCursor.getTypeId() == 0) && stackInSlot.getTypeId() == 0) {
return; // Nothing to do
}
if (stackOnCursor.getTypeId() == 0 && stackInSlot.getTypeId() != 0 && button == 1) { // Split item
int amountSlot = stackInSlot.getAmount() / 2;
int amountCursor = stackInSlot.getAmount() - amountSlot;
if (stackInSlot.getAmount() == 1) {
amountSlot = 0;
amountCursor = 1;
}
stackOnCursor = stackInSlot.clone();
stackOnCursor.setAmount(amountCursor);
stackInSlot.setAmount(amountSlot);
if (amountSlot == 0) {
stackInSlot = new ItemStack(0);
}
boolean success = slot.onItemTake(stackOnCursor);
if (success) {
slot.setItem(stackInSlot);
} else {
return;
}
} else if (stackOnCursor != null && (stackInSlot.getTypeId() == 0 || (stackInSlot.getTypeId() == stackOnCursor.getTypeId() && stackInSlot.getDurability() == stackOnCursor.getDurability()))) { //Put item
ItemStack toPut = stackOnCursor.clone();
int putAmount = toPut.getAmount();
if (button == 1) {
putAmount = 1;
}
int amount = stackInSlot.getTypeId() == 0 ? 0 : stackInSlot.getAmount();
amount += putAmount;
int maxStackSize = toPut.getMaxStackSize();
if (maxStackSize == -1) {
maxStackSize = 64;
}
if (amount > maxStackSize) {
putAmount -= amount - maxStackSize;
amount = maxStackSize;
}
if (putAmount <= 0) {
return;
}
toPut.setAmount(putAmount);
boolean success = slot.onItemPut(toPut);
if (success) {
stackOnCursor.setAmount(stackOnCursor.getAmount() - putAmount);
if (stackOnCursor.getAmount() == 0) {
stackOnCursor = new ItemStack(0);
}
ItemStack put = toPut.clone();
put.setAmount(amount);
slot.setItem(put);
}
} else if (stackOnCursor == null || stackOnCursor.getTypeId() == 0) { // Take item or shift click
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
slot.onItemShiftClicked();
} else { // Take item
boolean success = slot.onItemTake(stackInSlot);
if (success) {
stackOnCursor = stackInSlot;
slot.setItem(new ItemStack(0));
}
}
} else if (stackOnCursor.getTypeId() != stackInSlot.getTypeId() || stackOnCursor.getDurability() != stackInSlot.getDurability()) { // Exchange slot stack and cursor stack
boolean success = slot.onItemExchange(stackInSlot, stackOnCursor.clone());
if (success) {