mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-25 14:34:22 +00:00
CraftingStation side chest now work with any IInventory with a configurable blacklist. (#35)
* CraftingStation side chest now work with any IInventory with a configurable blacklist. * Check ISidedInventory and accessible slots. Still needs some work for shift clicking. * Backport shift click behavior and some helper functions * Fix NEI overlap, and tinker's tool station integration * Fix NEI shift clicking by redoing math
This commit is contained in:
1 parent
1c305ff293
commit
1c46541223
14 files changed
+1455
-499
No files matched your search
@@ -1,12 +1,12 @@
|
||||
package tconstruct.tools.inventory;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -16,25 +16,34 @@ import net.minecraft.world.World;
|
||||
import tconstruct.library.crafting.ModifyBuilder;
|
||||
import tconstruct.library.modifier.IModifyable;
|
||||
import tconstruct.tools.TinkerTools;
|
||||
import tconstruct.tools.gui.ChestSlot;
|
||||
import tconstruct.tools.logic.CraftingStationLogic;
|
||||
|
||||
public class CraftingStationContainer extends Container
|
||||
{
|
||||
/** The crafting matrix inventory (3x3). */
|
||||
public InventoryCrafting craftMatrix;// = new InventoryCrafting(this, 3, 3);
|
||||
public IInventory craftResult;// = new InventoryCraftResult();
|
||||
public CraftingStationLogic logic;
|
||||
private World worldObj;
|
||||
EntityPlayer player;
|
||||
private int posX;
|
||||
private int posY;
|
||||
private int posZ;
|
||||
private WeakReference[] inventories;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public CraftingStationContainer(InventoryPlayer inventorplayer, CraftingStationLogic logic, int x, int y, int z)
|
||||
{
|
||||
public class CraftingStationContainer extends Container {
|
||||
private final World worldObj;
|
||||
private final int posX;
|
||||
private final int posY;
|
||||
private final int posZ;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final WeakReference [] inventories;
|
||||
|
||||
/**
|
||||
* The crafting matrix inventory (3x3).
|
||||
*/
|
||||
public InventoryCrafting craftMatrix;
|
||||
public IInventory craftResult;
|
||||
public CraftingStationLogic logic;
|
||||
EntityPlayer player;
|
||||
|
||||
public CraftingStationContainer(InventoryPlayer inventoryplayer, CraftingStationLogic logic, int x, int y, int z) {
|
||||
this.worldObj = logic.getWorldObj();
|
||||
this.player = inventorplayer.player;
|
||||
this.player = inventoryplayer.player;
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.posZ = z;
|
||||
@@ -43,75 +52,194 @@ public class CraftingStationContainer extends Container
|
||||
craftResult = new InventoryCraftingStationResult(logic);
|
||||
this.inventories = logic.getInventories();
|
||||
|
||||
int row;
|
||||
int column;
|
||||
int row, col;
|
||||
|
||||
int craftingOffsetX = 30;
|
||||
int inventoryOffsetX = 8;
|
||||
int bothOffset = 0;
|
||||
|
||||
if (logic.chest != null) {
|
||||
if(logic.slotCount > 54)
|
||||
bothOffset += 12; // SlideBar.width
|
||||
|
||||
if (logic.chest != null)
|
||||
{
|
||||
craftingOffsetX += 116;
|
||||
inventoryOffsetX += 116;
|
||||
bothOffset += 122;
|
||||
}
|
||||
final int craftingOffsetX = 30 + bothOffset;
|
||||
final int inventoryOffsetX = 8 + bothOffset;
|
||||
|
||||
|
||||
// 0 - crafting slot
|
||||
this.addSlotToContainer(new SlotCraftingStation(inventoryplayer.player, this.craftMatrix, this.craftResult, 0, craftingOffsetX + 94, 35));
|
||||
|
||||
this.addSlotToContainer(new SlotCraftingStation(inventorplayer.player, this.craftMatrix, this.craftResult, 0, craftingOffsetX + 94, 35));
|
||||
|
||||
for (row = 0; row < 3; ++row)
|
||||
{
|
||||
for (column = 0; column < 3; ++column)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, column + row * 3, craftingOffsetX + column * 18, 17 + row * 18));
|
||||
// 1 - 9 - Crafting Matrix
|
||||
for (row = 0; row < 3; ++row) {
|
||||
for (col = 0; col < 3; ++col) {
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, col + row * 3, craftingOffsetX + col * 18, 17 + row * 18));
|
||||
}
|
||||
}
|
||||
|
||||
//Player Inventory
|
||||
for (row = 0; row < 3; ++row)
|
||||
{
|
||||
for (column = 0; column < 9; ++column)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventorplayer, column + row * 9 + 9, inventoryOffsetX + column * 18, 84 + row * 18));
|
||||
// Player Inventory 10 - 36
|
||||
for (row = 0; row < 3; ++row) {
|
||||
for (col = 0; col < 9; ++col) {
|
||||
this.addSlotToContainer(new Slot(inventoryplayer, col + row * 9 + 9, inventoryOffsetX + col * 18, 84 + row * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (column = 0; column < 9; ++column)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventorplayer, column, inventoryOffsetX + column * 18, 142));
|
||||
// Player Hotbar - 37 - 45
|
||||
for (col = 0; col < 9; ++col) {
|
||||
this.addSlotToContainer(new Slot(inventoryplayer, col, inventoryOffsetX + col * 18, 142));
|
||||
}
|
||||
|
||||
//Side inventory
|
||||
if (logic.chest != null)
|
||||
{
|
||||
IInventory firstChest = logic.chest.get();
|
||||
IInventory secondChest = logic.doubleChest == null ? null : logic.doubleChest.get();
|
||||
// Side inventory - 46+
|
||||
if (logic.chest != null) {
|
||||
IInventory inv = logic.getFirstInventory();
|
||||
IInventory secondInv = logic.getSecondInventory();
|
||||
|
||||
if (logic.doubleFirst && logic.doubleChest != null)
|
||||
{
|
||||
secondChest = logic.chest.get();
|
||||
firstChest = logic.doubleChest.get();
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (column = 0; column < 9; column++)
|
||||
{
|
||||
for (row = 0; row < 6; row++)
|
||||
{
|
||||
int value = count < 27 ? count : count - 27;
|
||||
this.addSlotToContainer(new Slot(count < 27 ? firstChest : secondChest, value, 8 + row * 18, 19 + column * 18));
|
||||
count++;
|
||||
if (count >= 27 && secondChest == null)
|
||||
break;
|
||||
final Set<Integer> accessibleSlots = inv instanceof ISidedInventory ? new HashSet<>(Ints.asList(((ISidedInventory) inv).getAccessibleSlotsFromSide(logic.chestDirection.getOpposite().ordinal()))) : null;
|
||||
|
||||
int index = 0, curIndex = 0;
|
||||
IInventory curInv;
|
||||
final int invSize = inv.getSizeInventory() * (secondInv != null ? 2 : 1);
|
||||
for (row = 0; row < logic.invRows; row++) {
|
||||
for (col = 0; col < logic.invColumns; col++) {
|
||||
if(index >= invSize) break;
|
||||
// Adjust the inventory to account for double chests
|
||||
curInv = secondInv != null && index >= 27 ? secondInv : inv;
|
||||
// Adjust the index for the inventory
|
||||
curIndex = secondInv != null && index >= 27 ? index - 27 : index;
|
||||
|
||||
if(accessibleSlots == null || accessibleSlots.contains(curIndex)) {
|
||||
this.addSlotToContainer(new ChestSlot(curInv, curIndex, 8 + col * 18, 19 + row * 18));
|
||||
}
|
||||
index++;
|
||||
}
|
||||
if (count >= 27 && secondChest == null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.onCraftMatrixChanged(this.craftMatrix);
|
||||
}
|
||||
|
||||
public void onCraftMatrixChanged (IInventory par1IInventory)
|
||||
{
|
||||
public ItemStack modifyItem() {
|
||||
ItemStack input = craftMatrix.getStackInSlot(4);
|
||||
if (input != null) {
|
||||
Item item = input.getItem();
|
||||
if (item instanceof IModifyable) {
|
||||
ItemStack[] slots = new ItemStack[8];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
slots[i] = craftMatrix.getStackInSlot(i);
|
||||
slots[i + 4] = craftMatrix.getStackInSlot(i + 5);
|
||||
}
|
||||
return ModifyBuilder.instance.modifyItem(input, slots);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int index) {
|
||||
Slot slot = (Slot) this.inventorySlots.get(index);
|
||||
|
||||
if(slot == null || !slot.getHasStack()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack ret = slot.getStack().copy();
|
||||
ItemStack itemstack = slot.getStack().copy();
|
||||
|
||||
boolean nothingDone = true;
|
||||
|
||||
if (index == 0) {
|
||||
// Crafting Result
|
||||
if (ret.getItem() instanceof IModifyable) {
|
||||
nothingDone &= this.mergeCraftedStack(itemstack, logic.getSizeInventory(), this.inventorySlots.size(), true, entityPlayer);
|
||||
} else {
|
||||
// First refill the attached chests
|
||||
nothingDone &= this.refillChest(itemstack);
|
||||
|
||||
// Then try moving to player inventory
|
||||
nothingDone &= moveToPlayerInventory(itemstack);
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack, ret);
|
||||
} else if(index >= 1 && index < 10) { // From Crafting Grid
|
||||
// First refill the attached chests
|
||||
nothingDone &= this.refillChest(itemstack);
|
||||
|
||||
// Then try moving to player inventory
|
||||
nothingDone &= moveToPlayerInventory(itemstack);
|
||||
}
|
||||
else if (index >= 10 && index < 46) { // From Player Inv or Hotbar
|
||||
// First to the crafting Matrix
|
||||
nothingDone &= moveToCraftingGrid(itemstack);
|
||||
|
||||
// Then to any attached chest
|
||||
nothingDone &= this.moveToChest(itemstack);
|
||||
} else { // From the Attached Chests
|
||||
// First to the crafting Matrix
|
||||
nothingDone &= moveToCraftingGrid(itemstack);
|
||||
|
||||
// Then To Player Inv or Hotbar
|
||||
nothingDone &= moveToPlayerInventory(itemstack);
|
||||
}
|
||||
|
||||
if(nothingDone) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack.stackSize == ret.stackSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(entityPlayer, itemstack);
|
||||
|
||||
return ret;
|
||||
}
|
||||
protected boolean refillChest(ItemStack itemstack) {
|
||||
if(itemstack == null || itemstack.stackSize <= 0 || logic.slotCount == 0) return false;
|
||||
|
||||
return !this.mergeItemStackRefill(itemstack, 46, 46 + logic.slotCount, false);
|
||||
}
|
||||
|
||||
protected boolean moveToChest(ItemStack itemstack) {
|
||||
if(itemstack == null || itemstack.stackSize <= 0 || logic.slotCount == 0) return false;
|
||||
|
||||
return !this.mergeItemStack(itemstack, 46, 46 + logic.slotCount, false);
|
||||
}
|
||||
|
||||
protected boolean moveToPlayerInventory(ItemStack itemstack) {
|
||||
if(itemstack == null || itemstack.stackSize <= 0) return false;
|
||||
|
||||
return !this.mergeItemStack(itemstack, 10, 46, false);
|
||||
}
|
||||
|
||||
protected boolean moveToCraftingGrid(ItemStack itemstack) {
|
||||
if(itemstack == null || itemstack.stackSize <= 0) return false;
|
||||
|
||||
return !this.mergeItemStack(itemstack, 1, 10, true);
|
||||
}
|
||||
|
||||
public boolean func_94530_a/*canMergeSlot*/(ItemStack par1ItemStack, Slot par2Slot) {
|
||||
return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
|
||||
super.onContainerClosed(par1EntityPlayer);
|
||||
|
||||
if (!this.worldObj.isRemote) {
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
|
||||
|
||||
if (itemstack != null) {
|
||||
par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onCraftMatrixChanged(IInventory par1IInventory) {
|
||||
ItemStack tool = modifyItem();
|
||||
if (tool != null)
|
||||
this.craftResult.setInventorySlotContents(0, tool);
|
||||
@@ -119,51 +247,8 @@ public class CraftingStationContainer extends Container
|
||||
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
|
||||
}
|
||||
|
||||
public ItemStack modifyItem ()
|
||||
{
|
||||
ItemStack input = craftMatrix.getStackInSlot(4);
|
||||
if (input != null)
|
||||
{
|
||||
Item item = input.getItem();
|
||||
if (item instanceof IModifyable)
|
||||
{
|
||||
ItemStack[] slots = new ItemStack[8];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
slots[i] = craftMatrix.getStackInSlot(i);
|
||||
slots[i + 4] = craftMatrix.getStackInSlot(i + 5);
|
||||
}
|
||||
ItemStack output = ModifyBuilder.instance.modifyItem(input, slots);
|
||||
if (output != null)
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed (EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
super.onContainerClosed(par1EntityPlayer);
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
|
||||
|
||||
if (itemstack != null)
|
||||
{
|
||||
par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith (EntityPlayer player)
|
||||
{
|
||||
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
Block block = worldObj.getBlock(this.posX, this.posY, this.posZ);
|
||||
if (block != TinkerTools.craftingStationWood && block != TinkerTools.craftingSlabWood)
|
||||
return false;
|
||||
@@ -174,105 +259,23 @@ public class CraftingStationContainer extends Container
|
||||
return player.getDistanceSq((double) this.posX + 0.5D, (double) this.posY + 0.5D, (double) this.posZ + 0.5D) <= 64.0D;
|
||||
}
|
||||
|
||||
public ItemStack transferStackInSlot (EntityPlayer par1EntityPlayer, int par2)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(par2);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (par2 == 0)
|
||||
{
|
||||
if (itemstack.getItem() instanceof IModifyable)
|
||||
{
|
||||
if (!this.mergeCraftedStack(itemstack1, logic.getSizeInventory(), this.inventorySlots.size(), true, par1EntityPlayer))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 10, 46, true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
}
|
||||
else if (par2 >= 10 && par2 < 37)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 37, 46, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (par2 >= 37 && par2 < 46)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 10, 37, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 10, 46, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack) null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
protected boolean mergeCraftedStack (ItemStack stack, int slotsStart, int slotsTotal, boolean playerInventory, EntityPlayer player)
|
||||
{
|
||||
protected boolean mergeCraftedStack(ItemStack stack, int slotsStart, int slotsTotal, boolean playerInventory, EntityPlayer player) {
|
||||
boolean failedToMerge = false;
|
||||
int slotIndex = slotsStart;
|
||||
|
||||
if (playerInventory)
|
||||
{
|
||||
if (playerInventory) {
|
||||
slotIndex = slotsTotal - 1;
|
||||
}
|
||||
|
||||
Slot otherInventorySlot;
|
||||
ItemStack copyStack = null;
|
||||
ItemStack copyStack;
|
||||
|
||||
if (stack.stackSize > 0)
|
||||
{
|
||||
if (playerInventory)
|
||||
{
|
||||
slotIndex = slotsTotal - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
slotIndex = slotsStart;
|
||||
}
|
||||
|
||||
while (!playerInventory && slotIndex < slotsTotal || playerInventory && slotIndex >= slotsStart)
|
||||
{
|
||||
if (stack.stackSize > 0) {
|
||||
while (!playerInventory && slotIndex < slotsTotal || playerInventory && slotIndex >= slotsStart) {
|
||||
otherInventorySlot = (Slot) this.inventorySlots.get(slotIndex);
|
||||
copyStack = otherInventorySlot.getStack();
|
||||
|
||||
if (copyStack == null)
|
||||
{
|
||||
if (copyStack == null) {
|
||||
otherInventorySlot.putStack(stack.copy());
|
||||
otherInventorySlot.onSlotChanged();
|
||||
stack.stackSize = 0;
|
||||
@@ -280,12 +283,9 @@ public class CraftingStationContainer extends Container
|
||||
break;
|
||||
}
|
||||
|
||||
if (playerInventory)
|
||||
{
|
||||
if (playerInventory) {
|
||||
--slotIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
++slotIndex;
|
||||
}
|
||||
}
|
||||
@@ -294,8 +294,102 @@ public class CraftingStationContainer extends Container
|
||||
return failedToMerge;
|
||||
}
|
||||
|
||||
public boolean func_94530_a (ItemStack par1ItemStack, Slot par2Slot)
|
||||
{
|
||||
return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot);
|
||||
@Override
|
||||
protected boolean mergeItemStack(@Nonnull ItemStack stack, int startIndex, int endIndex, boolean useEndIndex) {
|
||||
boolean ret = mergeItemStackRefill(stack, startIndex, endIndex, useEndIndex);
|
||||
if(stack.stackSize > 0) {
|
||||
ret |= mergeItemStackMove(stack, startIndex, endIndex, useEndIndex);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// only refills items that are already present
|
||||
protected boolean mergeItemStackRefill(@Nonnull ItemStack stack, int startIndex, int endIndex, boolean useEndIndex) {
|
||||
if(stack.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean didSomething = false;
|
||||
int k = useEndIndex ? endIndex - 1 : startIndex;
|
||||
|
||||
|
||||
Slot slot;
|
||||
ItemStack itemstack1;
|
||||
|
||||
if(stack.isStackable()) {
|
||||
while(stack.stackSize > 0 && (!useEndIndex && k < endIndex || useEndIndex && k >= startIndex)) {
|
||||
slot = (Slot)this.inventorySlots.get(k);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if(itemstack1 != null
|
||||
&& itemstack1.getItem() == stack.getItem()
|
||||
&& (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage())
|
||||
&& ItemStack.areItemStackTagsEqual(stack, itemstack1)
|
||||
&& this.func_94530_a/*canMergeSlot*/(stack, slot)) {
|
||||
int l = itemstack1.stackSize + stack.stackSize;
|
||||
int limit = Math.min(stack.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
|
||||
if(l <= limit) {
|
||||
stack.stackSize = 0;
|
||||
itemstack1.stackSize = l;
|
||||
slot.onSlotChanged();
|
||||
didSomething = true;
|
||||
}
|
||||
else if(itemstack1.stackSize < limit) {
|
||||
stack.stackSize -= (limit - itemstack1.stackSize);
|
||||
itemstack1.stackSize = limit;
|
||||
slot.onSlotChanged();
|
||||
didSomething = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(useEndIndex) --k;
|
||||
else ++k;
|
||||
}
|
||||
}
|
||||
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
// only moves items into empty slots
|
||||
protected boolean mergeItemStackMove(@Nonnull ItemStack stack, int startIndex, int endIndex, boolean useEndIndex) {
|
||||
if(stack.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean didSomething = false;
|
||||
int k = useEndIndex ? endIndex - 1 : startIndex;
|
||||
|
||||
while(!useEndIndex && k < endIndex || useEndIndex && k >= startIndex) {
|
||||
final Slot slot = (Slot)this.inventorySlots.get(k);
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
|
||||
if((itemstack1 == null || itemstack1.stackSize == 0) && slot.isItemValid(stack) && this.func_94530_a/*canMergeSlot*/(stack, slot)) {
|
||||
// Forge: Make sure to respect isItemValid in the slot.
|
||||
int limit = slot.getSlotStackLimit();
|
||||
ItemStack stack2 = stack.copy();
|
||||
if(stack2.stackSize > limit) {
|
||||
stack2.stackSize = limit;
|
||||
stack.stackSize -= limit;
|
||||
}
|
||||
else {
|
||||
stack.stackSize = 0;
|
||||
}
|
||||
slot.putStack(stack2);
|
||||
slot.onSlotChanged();
|
||||
didSomething = true;
|
||||
|
||||
if(stack.stackSize <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(useEndIndex) --k;
|
||||
else ++k;
|
||||
}
|
||||
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user