diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerBreaker.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerBreaker.java index 161cb37ef..c4dcfb94c 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerBreaker.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerBreaker.java @@ -46,34 +46,32 @@ public class ContainerBreaker extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, 0, 9, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(!this.mergeItemStack(newStack, 0, 10, false)){ + // + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) + return null; } - - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCanolaPress.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCanolaPress.java index e4c244012..88278d433 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCanolaPress.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCanolaPress.java @@ -1,5 +1,6 @@ package ellpeck.actuallyadditions.inventory; +import ellpeck.actuallyadditions.blocks.InitBlocks; import ellpeck.actuallyadditions.inventory.slot.SlotOutput; import ellpeck.actuallyadditions.items.InitItems; import ellpeck.actuallyadditions.items.metalists.TheMiscItems; @@ -8,10 +9,11 @@ import ellpeck.actuallyadditions.tile.TileEntityCanolaPress; import invtweaks.api.container.InventoryContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; @InventoryContainer public class ContainerCanolaPress extends Container{ @@ -48,33 +50,33 @@ public class ContainerCanolaPress extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(currentStack.getItem() == InitItems.itemMisc && currentStack.getItemDamage() == TheMiscItems.CANOLA.ordinal()){ - this.mergeItemStack(newStack, 0, 1, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(newStack.getItem() == InitItems.itemMisc && newStack.getItemDamage() == TheMiscItems.CANOLA.ordinal()){ + if(!this.mergeItemStack(newStack, 0, 1, false)) return null; } - if(currentStack.getItem() == Items.bucket){ - this.mergeItemStack(newStack, 1, 2, false); + else if(FluidContainerRegistry.getContainerCapacity(new FluidStack(InitBlocks.fluidCanolaOil, 1), newStack) > 0){ + if(!this.mergeItemStack(newStack, 1, 2, false)) return null; } - } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); + if (newStack.stackSize == 0) theSlot.putStack(null); else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; + + if (newStack.stackSize == currentStack.stackSize) return null; theSlot.onPickupFromSlot(player, newStack); return currentStack; diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoalGenerator.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoalGenerator.java index 8204ad6ad..7f9979f20 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoalGenerator.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoalGenerator.java @@ -43,31 +43,30 @@ public class ContainerCoalGenerator extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(TileEntityFurnace.getItemBurnTime(currentStack) > 0){ - this.mergeItemStack(newStack, 0, 1, false); + if(theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(TileEntityFurnace.getItemBurnTime(newStack) > 0){ + if(!this.mergeItemStack(newStack, 0, 1, false)) return null; } - } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); + if (newStack.stackSize == 0) theSlot.putStack(null); else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; + + if (newStack.stackSize == currentStack.stackSize) return null; theSlot.onPickupFromSlot(player, newStack); return currentStack; diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoffeeMachine.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoffeeMachine.java index 436e6da47..89204c475 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoffeeMachine.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerCoffeeMachine.java @@ -60,45 +60,47 @@ public class ContainerCoffeeMachine extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(currentStack.getItem() == InitItems.itemCoffeeBean){ - this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS+1, false); - } - if(currentStack.getItem() == InitItems.itemMisc && currentStack.getItemDamage() == TheMiscItems.CUP.ordinal()){ - this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_INPUT, TileEntityCoffeeMachine.SLOT_INPUT+1, false); - } - if(ItemCoffee.getIngredientFromStack(newStack) != null){ - this.mergeItemStack(newStack, 3, 10, false); - } - if(FluidContainerRegistry.containsFluid(newStack, new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME))){ - this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_WATER_INPUT, TileEntityCoffeeMachine.SLOT_WATER_INPUT+1, false); - } - } + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + //Slots in Inventory to shift from + if(slot == TileEntityCoffeeMachine.SLOT_OUTPUT){ + if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)) return null; + theSlot.onSlotChange(newStack, currentStack); } + //Other Slots in Inventory excluded + else if(slot >= inventoryStart){ + //Shift from Inventory + if(newStack.getItem() == InitItems.itemMisc && newStack.getItemDamage() == TheMiscItems.CUP.ordinal()){ + if(!this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_INPUT, TileEntityCoffeeMachine.SLOT_INPUT+1, false)) return null; + } + else if(FluidContainerRegistry.containsFluid(newStack, new FluidStack(FluidRegistry.WATER, 1))){ + if(!this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_WATER_INPUT, TileEntityCoffeeMachine.SLOT_WATER_INPUT+1, false)) return null; + } + else if(ItemCoffee.getIngredientFromStack(newStack) != null){ + if(!this.mergeItemStack(newStack, 3, 11, false)) return null; + } + else if(newStack.getItem() == InitItems.itemCoffeeBean){ + if(!this.mergeItemStack(newStack, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS, TileEntityCoffeeMachine.SLOT_COFFEE_BEANS+1, false)) return null; + } + // + + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDrill.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDrill.java index b8a3d30dc..6b103f7b0 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDrill.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDrill.java @@ -78,36 +78,33 @@ public class ContainerDrill extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(currentStack.getItem() instanceof ItemDrillUpgrade){ - this.mergeItemStack(newStack, 0, SLOT_AMOUNT, false); - } + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(newStack.getItem() instanceof ItemDrillUpgrade){ + if(!this.mergeItemStack(newStack, 0, 5, false)) return null; } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDropper.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDropper.java index 095a9e254..4313158f1 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDropper.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerDropper.java @@ -46,34 +46,32 @@ public class ContainerDropper extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, 0, 9, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(!this.mergeItemStack(newStack, 0, 10, false)){ + // + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) + return null; } - - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnergizer.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnergizer.java index 7b88403a5..f806b1c42 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnergizer.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnergizer.java @@ -70,29 +70,35 @@ public class ContainerEnergizer extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(currentStack.getItem() instanceof IEnergyContainerItem){ - this.mergeItemStack(newStack, 0, 1, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Slots in Inventory to shift from + if(slot == 1){ + if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)) return null; + theSlot.onSlotChange(newStack, currentStack); + } + //Other Slots in Inventory excluded + else if(slot >= inventoryStart){ + //Shift from Inventory + if(newStack.getItem() instanceof IEnergyContainerItem){ + if(!this.mergeItemStack(newStack, 0, 1, false)) return null; } - } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; - if(newStack.stackSize == 0) theSlot.putStack(null); + if (newStack.stackSize == 0) theSlot.putStack(null); else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; + + if (newStack.stackSize == currentStack.stackSize) return null; theSlot.onPickupFromSlot(player, newStack); return currentStack; diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnervator.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnervator.java index 529d8c2df..d9aba92d0 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnervator.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerEnervator.java @@ -61,7 +61,6 @@ public class ContainerEnervator extends Container{ return this.enervator.isUseableByPlayer(player); } - //TODO Armor Shift-Clicking @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot){ final int inventoryStart = 2; @@ -70,31 +69,35 @@ public class ContainerEnervator extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(currentStack.getItem() instanceof IEnergyContainerItem){ - this.mergeItemStack(newStack, 0, 1, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Slots in Inventory to shift from + if(slot == 1){ + if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)) return null; + theSlot.onSlotChange(newStack, currentStack); + } + //Other Slots in Inventory excluded + else if(slot >= inventoryStart){ + //Shift from Inventory + if(newStack.getItem() instanceof IEnergyContainerItem){ + if(!this.mergeItemStack(newStack, 0, 1, false)) return null; } - } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); + if (newStack.stackSize == 0) theSlot.putStack(null); else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; + + if (newStack.stackSize == currentStack.stackSize) return null; theSlot.onPickupFromSlot(player, newStack); return currentStack; diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFeeder.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFeeder.java index 99d73bca8..37a5e3451 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFeeder.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFeeder.java @@ -35,40 +35,38 @@ public class ContainerFeeder extends Container{ @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot){ - final int inventoryStart = 1; + final int inventoryStart = 9; final int inventoryEnd = inventoryStart+26; final int hotbarStart = inventoryEnd+1; final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, 0, 1, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(!this.mergeItemStack(newStack, 0, 1, false)){ + // + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) + return null; } - - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFermentingBarrel.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFermentingBarrel.java index c5d3d6a6e..6e614f6ad 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFermentingBarrel.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFermentingBarrel.java @@ -7,7 +7,6 @@ import ellpeck.actuallyadditions.tile.TileEntityFermentingBarrel; import invtweaks.api.container.InventoryContainer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -44,45 +43,42 @@ public class ContainerFermentingBarrel extends Container{ @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot){ - final int inventoryStart = 4; + final int inventoryStart = 3; final int inventoryEnd = inventoryStart+26; final int hotbarStart = inventoryEnd+1; final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(FluidContainerRegistry.containsFluid(currentStack, new FluidStack(InitBlocks.fluidCanolaOil, FluidContainerRegistry.BUCKET_VOLUME))){ - this.mergeItemStack(newStack, 0, 1, false); - } - if(currentStack.getItem() == Items.bucket){ - this.mergeItemStack(newStack, 2, 3, false); - } + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(FluidContainerRegistry.getContainerCapacity(new FluidStack(InitBlocks.fluidOil, 1), newStack) > 0){ + if(!this.mergeItemStack(newStack, 3, 4, false)) return null; } - - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + else if(FluidContainerRegistry.containsFluid(newStack, new FluidStack(InitBlocks.fluidCanolaOil, 1))){ + if(!this.mergeItemStack(newStack, 1, 2, false)) return null; } + // - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFluidCollector.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFluidCollector.java index 4b1ce7ddb..39422469b 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFluidCollector.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFluidCollector.java @@ -45,43 +45,38 @@ public class ContainerFluidCollector extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(this.collector.isPlacer){ - if(FluidContainerRegistry.isBucket(currentStack) && !newStack.isItemEqual(FluidContainerRegistry.EMPTY_BUCKET)){ - this.mergeItemStack(newStack, 0, 1, false); - } - } - else{ - if(newStack.isItemEqual(FluidContainerRegistry.EMPTY_BUCKET)){ - this.mergeItemStack(newStack, 0, 1, false); - } - } - } + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + //Slots in Inventory to shift from + if(slot == 1){ + if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)) return null; + theSlot.onSlotChange(newStack, currentStack); } + //Other Slots in Inventory excluded + else if(slot >= inventoryStart){ + //Shift from Inventory + if(FluidContainerRegistry.isEmptyContainer(newStack)){ + if(!this.mergeItemStack(newStack, 0, 1, false)) return null; + } + // + + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFurnaceDouble.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFurnaceDouble.java index 1996e0e38..4fc95e36f 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFurnaceDouble.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerFurnaceDouble.java @@ -1,6 +1,7 @@ package ellpeck.actuallyadditions.inventory; import ellpeck.actuallyadditions.inventory.slot.SlotOutput; +import ellpeck.actuallyadditions.recipe.CrusherRecipeManualRegistry; import ellpeck.actuallyadditions.tile.TileEntityBase; import ellpeck.actuallyadditions.tile.TileEntityFurnaceDouble; import invtweaks.api.container.InventoryContainer; @@ -9,7 +10,6 @@ import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.FurnaceRecipes; @InventoryContainer public class ContainerFurnaceDouble extends Container{ @@ -47,37 +47,40 @@ public class ContainerFurnaceDouble extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(FurnaceRecipes.smelting().getSmeltingResult(currentStack) != null){ - this.mergeItemStack(newStack, TileEntityFurnaceDouble.SLOT_INPUT_1, TileEntityFurnaceDouble.SLOT_INPUT_1+1, false); - this.mergeItemStack(newStack, TileEntityFurnaceDouble.SLOT_INPUT_2, TileEntityFurnaceDouble.SLOT_INPUT_2+2, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Slots in Inventory to shift from + if(slot == TileEntityFurnaceDouble.SLOT_OUTPUT_1 || slot == TileEntityFurnaceDouble.SLOT_OUTPUT_2){ + if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)) return null; + theSlot.onSlotChange(newStack, currentStack); + } + //Other Slots in Inventory excluded + else if(slot >= inventoryStart){ + //Shift from Inventory + if(CrusherRecipeManualRegistry.getOutput(newStack, false) != null){ + if(!this.mergeItemStack(newStack, TileEntityFurnaceDouble.SLOT_INPUT_1, TileEntityFurnaceDouble.SLOT_INPUT_1+1, false)){ + if(!this.mergeItemStack(newStack, TileEntityFurnaceDouble.SLOT_INPUT_2, TileEntityFurnaceDouble.SLOT_INPUT_2+1, false)) return null; } } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGiantChest.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGiantChest.java index 941b9ad60..59f332787 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGiantChest.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGiantChest.java @@ -46,34 +46,32 @@ public class ContainerGiantChest extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, 0, 117, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(!this.mergeItemStack(newStack, 0, 117, false)){ + // + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) + return null; } - - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java index 47cce16e2..e0c46e5e3 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java @@ -53,37 +53,42 @@ public class ContainerGrinder extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(CrusherRecipeManualRegistry.getOutput(currentStack, false) != null){ - this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_1, TileEntityGrinder.SLOT_INPUT_1+1, false); - if(this.isDouble) this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_2, TileEntityGrinder.SLOT_INPUT_2+1, false); - } - } + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + //Slots in Inventory to shift from + if(slot == TileEntityGrinder.SLOT_OUTPUT_1_1 || slot == TileEntityGrinder.SLOT_OUTPUT_1_2 || slot == TileEntityGrinder.SLOT_OUTPUT_2_1 || slot == TileEntityGrinder.SLOT_OUTPUT_2_2){ + if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, true)) return null; + theSlot.onSlotChange(newStack, currentStack); } + //Other Slots in Inventory excluded + else if(slot >= inventoryStart){ + //Shift from Inventory + if(CrusherRecipeManualRegistry.getOutput(newStack, false) != null){ + if(!this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_1, TileEntityGrinder.SLOT_INPUT_1+1, false)){ + if(this.tileGrinder.isDouble){ + if(!this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_2, TileEntityGrinder.SLOT_INPUT_2+1, false)) return null; + } + } + } + // + + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java index 56f95356a..a88d0ceaa 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerInputter.java @@ -51,40 +51,38 @@ public class ContainerInputter extends Container{ @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot){ - final int inventory = this.isAdvanced ? 25 : 1; - final int inventoryEnd = inventory+26; - final int hotbar = inventoryEnd+1; - final int hotbarEnd = hotbar+8; + final int inventoryStart = this.isAdvanced ? 25 : 1; + final int inventoryEnd = inventoryStart+26; + final int hotbarStart = inventoryEnd+1; + final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventory){ - this.mergeItemStack(newStack, 0, 1, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(!this.mergeItemStack(newStack, 0, 1, false)){ + // + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) + return null; } - - if(slot <= hotbarEnd && slot >= hotbar){ - this.mergeItemStack(newStack, inventory, inventoryEnd, false); - } - - else if(slot <= inventoryEnd && slot >= inventory){ - this.mergeItemStack(newStack, hotbar, hotbarEnd, false); - } - - else if(slot < inventory){ - this.mergeItemStack(newStack, inventory, hotbarEnd, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerOilGenerator.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerOilGenerator.java index 94c4c71c1..bea2ccd80 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerOilGenerator.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerOilGenerator.java @@ -47,36 +47,33 @@ public class ContainerOilGenerator extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(FluidContainerRegistry.containsFluid(currentStack, new FluidStack(InitBlocks.fluidOil, FluidContainerRegistry.BUCKET_VOLUME))){ - this.mergeItemStack(newStack, 0, 1, false); - } + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(FluidContainerRegistry.containsFluid(newStack, new FluidStack(InitBlocks.fluidOil, 1))){ + if(!this.mergeItemStack(newStack, 0, 1, false)) return null; } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerPhantomPlacer.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerPhantomPlacer.java index 613eb0628..ca09d525f 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerPhantomPlacer.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerPhantomPlacer.java @@ -46,34 +46,32 @@ public class ContainerPhantomPlacer extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, 0, 9, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(!this.mergeItemStack(newStack, 0, 10, false)){ + // + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) + return null; } - - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); - } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerRepairer.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerRepairer.java index 28ef60be8..feb6548c6 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerRepairer.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerRepairer.java @@ -44,36 +44,33 @@ public class ContainerRepairer extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= inventoryStart){ - if(TileEntityItemRepairer.canBeRepaired(currentStack)){ - this.mergeItemStack(newStack, TileEntityItemRepairer.SLOT_INPUT, TileEntityItemRepairer.SLOT_INPUT+1, false); - } + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(TileEntityItemRepairer.canBeRepaired(newStack)){ + if(!this.mergeItemStack(newStack, TileEntityItemRepairer.SLOT_INPUT, TileEntityItemRepairer.SLOT_INPUT+1, false)) return null; } + // - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerXPSolidifier.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerXPSolidifier.java index 04f0bd240..76461c9df 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerXPSolidifier.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerXPSolidifier.java @@ -43,30 +43,27 @@ public class ContainerXPSolidifier extends Container{ final int hotbarEnd = hotbarStart+8; Slot theSlot = (Slot)this.inventorySlots.get(slot); - if(theSlot.getHasStack()){ - ItemStack currentStack = theSlot.getStack(); - ItemStack newStack = currentStack.copy(); - if(currentStack.getItem() != null){ - if(slot <= hotbarEnd && slot >= hotbarStart){ - this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false); + if (theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)) return null; } - - else if(slot <= inventoryEnd && slot >= inventoryStart){ - this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false); - } - - else if(slot < inventoryStart){ - this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false); - } - - if(newStack.stackSize == 0) theSlot.putStack(null); - else theSlot.onSlotChanged(); - if(newStack.stackSize == currentStack.stackSize) return null; - theSlot.onPickupFromSlot(player, newStack); - - return currentStack; + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; } + else if(!this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)) return null; + + if (newStack.stackSize == 0) theSlot.putStack(null); + else theSlot.onSlotChanged(); + + if (newStack.stackSize == currentStack.stackSize) return null; + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; } return null; } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemCoffee.java b/src/main/java/ellpeck/actuallyadditions/items/ItemCoffee.java index 79d6a425b..0f308b352 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemCoffee.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemCoffee.java @@ -129,7 +129,7 @@ public class ItemCoffee extends ItemFood implements INameableItem{ } public static PotionEffect[] getEffectsFromStack(ItemStack stack){ - ArrayList effects = new ArrayList(); + ArrayList effects = new ArrayList<>(); NBTTagCompound tag = stack.getTagCompound(); if(tag != null){ int counter = tag.getInteger("Counter"); diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityXPSolidifier.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityXPSolidifier.java index 8f03f4f7d..2061e0505 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityXPSolidifier.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityXPSolidifier.java @@ -77,18 +77,10 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I public void onButtonPressed(int buttonID, EntityPlayer player){ if(buttonID < this.buttonAmounts.length){ if(this.getPlayerXP(player) > 0){ - if(this.buttonAmounts[buttonID] != -999){ - if(this.amount < Short.MAX_VALUE-this.buttonAmounts[buttonID] && this.getPlayerXP(player) >= ItemSpecialDrop.SOLID_XP_AMOUNT*this.buttonAmounts[buttonID]){ - this.addPlayerXP(player, -(ItemSpecialDrop.SOLID_XP_AMOUNT*this.buttonAmounts[buttonID])); - if(!worldObj.isRemote) this.amount += this.buttonAmounts[buttonID]; - } - } - else{ - int xp = this.getPlayerXP(player)/ItemSpecialDrop.SOLID_XP_AMOUNT; - if(this.amount < Short.MAX_VALUE-xp){ - this.addPlayerXP(player, -(xp*ItemSpecialDrop.SOLID_XP_AMOUNT)); - if(!worldObj.isRemote) this.amount += xp; - } + int xp = this.buttonAmounts[buttonID] == -999 ? this.getPlayerXP(player)/ItemSpecialDrop.SOLID_XP_AMOUNT : this.buttonAmounts[buttonID]; + if(this.amount < Short.MAX_VALUE-xp && this.getPlayerXP(player) >= ItemSpecialDrop.SOLID_XP_AMOUNT*xp){ + this.addPlayerXP(player, -(ItemSpecialDrop.SOLID_XP_AMOUNT*xp)); + if(!worldObj.isRemote) this.amount += xp; } } }