#1011 Shift-clicking armor from a Capacitor Bank's charge slots will re-equip the item if possible

This commit is contained in:
CrazyPants committed 2014-11-26 21:03:00 +08:00
1 parent a770eb7401
commit 976f719b46
2 files changed
+22 -5

No files matched your search

@@ -50,12 +50,12 @@ public class ContainerCapacitorBank extends Container {
// add players inventory
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, + armorOffset + 8 + j * 18, 84 + i * 18));
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, +armorOffset + 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; ++i) {
addSlotToContainer(new Slot(playerInv, i, + armorOffset + 8 + i * 18, 142));
addSlotToContainer(new Slot(playerInv, i, +armorOffset + 8 + i * 18, 142));
}
//armor slots
@@ -108,8 +108,10 @@ public class ContainerCapacitorBank extends Container {
if(slotIndex < 4) {
// merge from machine input slots to inventory
if(!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, false)) {
return null;
if(!mergeItemStackIntoArmor(entityPlayer, origStack, slotIndex)) {
if(!mergeItemStack(origStack, startPlayerSlot, endHotBarSlot, false)) {
return null;
}
}
} else {
@@ -149,4 +151,19 @@ public class ContainerCapacitorBank extends Container {
return copystack;
}
private boolean mergeItemStackIntoArmor(EntityPlayer entityPlayer, ItemStack origStack, int slotIndex) {
if(origStack == null || !(origStack.getItem() instanceof ItemArmor)) {
return false;
}
ItemArmor armor = (ItemArmor) origStack.getItem();
int index = 3 - armor.armorType;
ItemStack[] ai = entityPlayer.inventory.armorInventory;
if(ai[index] == null) {
ai[index] = origStack.copy();
origStack.stackSize = 0;
return true;
}
return false;
}
}