mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-20 20:22:36 +00:00
Fix JABBA-related issues with crafting station slots (#54)
* Fix shift-merging tools voiding items fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11392> * Change 0-sized ItemStacks into null stacks in crafting station attached slots Fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/10425> * Update buildscript * spotlessApply
This commit is contained in:
1 parent
18bfeaff32
commit
39be06c23b
571 files changed
+25959
-28223
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package tconstruct.tools.inventory;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.lang.ref.WeakReference;
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -19,24 +20,20 @@ import tconstruct.tools.TinkerTools;
|
||||
import tconstruct.tools.gui.ChestSlot;
|
||||
import tconstruct.tools.logic.CraftingStationLogic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
|
||||
private final WeakReference[] inventories;
|
||||
|
||||
/**
|
||||
* The crafting matrix inventory (3x3).
|
||||
*/
|
||||
public InventoryCrafting craftMatrix;
|
||||
|
||||
public IInventory craftResult;
|
||||
public CraftingStationLogic logic;
|
||||
EntityPlayer player;
|
||||
@@ -55,31 +52,32 @@ public class CraftingStationContainer extends Container {
|
||||
int row, col;
|
||||
|
||||
int bothOffset = 0;
|
||||
|
||||
|
||||
if (logic.chest != null) {
|
||||
if(logic.slotCount > 54)
|
||||
bothOffset += 12; // SlideBar.width
|
||||
if (logic.slotCount > 54) bothOffset += 12; // SlideBar.width
|
||||
|
||||
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(
|
||||
inventoryplayer.player, this.craftMatrix, this.craftResult, 0, craftingOffsetX + 94, 35));
|
||||
|
||||
// 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));
|
||||
this.addSlotToContainer(
|
||||
new Slot(this.craftMatrix, col + row * 3, craftingOffsetX + col * 18, 17 + 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));
|
||||
this.addSlotToContainer(
|
||||
new Slot(inventoryplayer, col + row * 9 + 9, inventoryOffsetX + col * 18, 84 + row * 18));
|
||||
}
|
||||
}
|
||||
// Player Hotbar - 37 - 45
|
||||
@@ -93,20 +91,22 @@ public class CraftingStationContainer extends Container {
|
||||
IInventory secondInv = logic.getSecondInventory();
|
||||
|
||||
final int accessSide = logic.chestDirection.getOpposite().ordinal();
|
||||
final int[] accessibleSlots = inv instanceof ISidedInventory ? ((ISidedInventory) inv).getAccessibleSlotsFromSide(accessSide) : null;
|
||||
|
||||
final int[] accessibleSlots = inv instanceof ISidedInventory
|
||||
? ((ISidedInventory) inv).getAccessibleSlotsFromSide(accessSide)
|
||||
: null;
|
||||
|
||||
int index = 0, curIndex = 0;
|
||||
IInventory curInv;
|
||||
final int invSize = inv.getSizeInventory() * (secondInv != null ? 2 : 1);
|
||||
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;
|
||||
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) {
|
||||
if (accessibleSlots != null) {
|
||||
if (curIndex >= accessibleSlots.length) {
|
||||
break;
|
||||
} else {
|
||||
@@ -114,7 +114,8 @@ public class CraftingStationContainer extends Container {
|
||||
}
|
||||
}
|
||||
|
||||
this.addSlotToContainer(new ChestSlot(curInv, curIndex, index, 8 + col * 18, 19 + row * 18, accessSide));
|
||||
this.addSlotToContainer(
|
||||
new ChestSlot(curInv, curIndex, index, 8 + col * 18, 19 + row * 18, accessSide));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@@ -141,20 +142,21 @@ public class CraftingStationContainer extends Container {
|
||||
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int index) {
|
||||
Slot slot = (Slot) this.inventorySlots.get(index);
|
||||
|
||||
if(slot == null || !slot.getHasStack()) {
|
||||
|
||||
if (slot == null || !slot.getHasStack()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
ItemStack itemstack = slot.getStack();
|
||||
ItemStack ret = itemstack.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);
|
||||
nothingDone &= !this.mergeCraftedStack(
|
||||
itemstack, logic.getSizeInventory(), this.inventorySlots.size(), true, entityPlayer);
|
||||
} else {
|
||||
// First refill the attached chests
|
||||
nothingDone &= this.refillChest(itemstack);
|
||||
@@ -164,20 +166,19 @@ public class CraftingStationContainer extends Container {
|
||||
}
|
||||
|
||||
slot.onSlotChange(itemstack, ret);
|
||||
} else if(index >= 1 && index < 10) { // From Crafting Grid
|
||||
} 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
|
||||
} 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
|
||||
} else { // From the Attached Chests
|
||||
// First to the crafting Matrix
|
||||
nothingDone &= moveToCraftingGrid(itemstack);
|
||||
|
||||
@@ -185,10 +186,10 @@ public class CraftingStationContainer extends Container {
|
||||
nothingDone &= moveToPlayerInventory(itemstack);
|
||||
}
|
||||
|
||||
if(nothingDone) {
|
||||
if (nothingDone) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (itemstack.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
@@ -203,31 +204,32 @@ public class CraftingStationContainer extends Container {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected boolean refillChest(ItemStack itemstack) {
|
||||
if(itemstack == null || itemstack.stackSize <= 0 || logic.slotCount == 0) return false;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
public boolean func_94530_a /*canMergeSlot*/(ItemStack par1ItemStack, Slot par2Slot) {
|
||||
return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot);
|
||||
}
|
||||
|
||||
@@ -248,25 +250,26 @@ public class CraftingStationContainer extends Container {
|
||||
|
||||
public void onCraftMatrixChanged(IInventory par1IInventory) {
|
||||
ItemStack tool = modifyItem();
|
||||
if (tool != null)
|
||||
this.craftResult.setInventorySlotContents(0, tool);
|
||||
if (tool != null) this.craftResult.setInventorySlotContents(0, tool);
|
||||
else
|
||||
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
|
||||
this.craftResult.setInventorySlotContents(
|
||||
0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
Block block = worldObj.getBlock(this.posX, this.posY, this.posZ);
|
||||
if (block != TinkerTools.craftingStationWood && block != TinkerTools.craftingSlabWood)
|
||||
return false;
|
||||
if (block != TinkerTools.craftingStationWood && block != TinkerTools.craftingSlabWood) return false;
|
||||
|
||||
if (!this.logic.isUseableByPlayer(player) || !CraftingStationLogic.isUseableByPlayer(player, this.inventories))
|
||||
return false;
|
||||
|
||||
return player.getDistanceSq((double) this.posX + 0.5D, (double) this.posY + 0.5D, (double) this.posZ + 0.5D) <= 64.0D;
|
||||
return player.getDistanceSq((double) this.posX + 0.5D, (double) this.posY + 0.5D, (double) this.posZ + 0.5D)
|
||||
<= 64.0D;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -282,7 +285,7 @@ public class CraftingStationContainer extends Container {
|
||||
otherInventorySlot = (Slot) this.inventorySlots.get(slotIndex);
|
||||
copyStack = otherInventorySlot.getStack();
|
||||
|
||||
if (copyStack == null) {
|
||||
if (copyStack == null && otherInventorySlot.isItemValid(stack)) {
|
||||
otherInventorySlot.putStack(stack.copy());
|
||||
otherInventorySlot.onSlotChanged();
|
||||
stack.stackSize = 0;
|
||||
@@ -304,54 +307,53 @@ public class CraftingStationContainer extends Container {
|
||||
@Override
|
||||
protected boolean mergeItemStack(@Nonnull ItemStack stack, int startIndex, int endIndex, boolean useEndIndex) {
|
||||
boolean ret = mergeItemStackRefill(stack, startIndex, endIndex, useEndIndex);
|
||||
if(stack.stackSize > 0) {
|
||||
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) {
|
||||
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);
|
||||
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)) {
|
||||
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) {
|
||||
if (l <= limit) {
|
||||
stack.stackSize = 0;
|
||||
itemstack1.stackSize = l;
|
||||
slot.onSlotChanged();
|
||||
didSomething = true;
|
||||
}
|
||||
else if(itemstack1.stackSize < limit) {
|
||||
} else if (itemstack1.stackSize < limit) {
|
||||
stack.stackSize -= (limit - itemstack1.stackSize);
|
||||
itemstack1.stackSize = limit;
|
||||
slot.onSlotChanged();
|
||||
didSomething = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(useEndIndex) --k;
|
||||
else ++k;
|
||||
|
||||
if (useEndIndex) --k;
|
||||
else ++k;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,43 +362,42 @@ public class CraftingStationContainer extends Container {
|
||||
|
||||
// only moves items into empty slots
|
||||
protected boolean mergeItemStackMove(@Nonnull ItemStack stack, int startIndex, int endIndex, boolean useEndIndex) {
|
||||
if(stack.stackSize <= 0) {
|
||||
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);
|
||||
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)) {
|
||||
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) {
|
||||
if (stack2.stackSize > limit) {
|
||||
stack2.stackSize = limit;
|
||||
stack.stackSize -= limit;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
stack.stackSize = 0;
|
||||
}
|
||||
slot.putStack(stack2);
|
||||
slot.onSlotChanged();
|
||||
didSomething = true;
|
||||
|
||||
if(stack.stackSize <= 0) {
|
||||
if (stack.stackSize <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(useEndIndex) --k;
|
||||
else ++k;
|
||||
if (useEndIndex) --k;
|
||||
else ++k;
|
||||
}
|
||||
|
||||
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user