mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 11:49:14 +00:00
1 parent
9d8e572ac8
commit
07afdf63b1
3 files changed
+27
-6
No files matched your search
@@ -76,17 +76,20 @@ public class InventoryAdapter implements IInventory, INBTTagable {
|
||||
}
|
||||
|
||||
public boolean tryAddStacksCopy(ItemStack[] stacks, boolean all) {
|
||||
return tryAddStacksCopy(stacks, 0, this.getSizeInventory(), all);
|
||||
}
|
||||
|
||||
public boolean tryAddStacksCopy(ItemStack[] stacks, int startSlot, int slots, boolean all) {
|
||||
|
||||
boolean addedAll = true;
|
||||
for (ItemStack stack : stacks) {
|
||||
if (stack == null)
|
||||
continue;
|
||||
|
||||
if (!tryAddStack(stack.copy(), all))
|
||||
addedAll = false;
|
||||
if (!tryAddStack(stack.copy(), startSlot, slots, all))
|
||||
return false;
|
||||
}
|
||||
|
||||
return addedAll;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean tryAddStacks(ItemStack[] stacks, boolean all) {
|
||||
@@ -121,7 +124,11 @@ public class InventoryAdapter implements IInventory, INBTTagable {
|
||||
}
|
||||
|
||||
public boolean tryAddStack(ItemStack stack, int startSlot, int slots, boolean all, boolean doAdd) {
|
||||
return addStack(stack, startSlot, slots, all, doAdd) > 0;
|
||||
int added = addStack(stack, startSlot, slots, all, doAdd);
|
||||
if (all)
|
||||
return added == stack.stackSize;
|
||||
else
|
||||
return added > 0;
|
||||
}
|
||||
|
||||
public int addStack(ItemStack stack, boolean all, boolean doAdd) {
|
||||
|
||||
@@ -286,13 +286,20 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
return (int) Math.floor(itemCount / tradegood.stackSize);
|
||||
}
|
||||
|
||||
public boolean canReceivePayment() {
|
||||
InventoryAdapter test = inventory.copy();
|
||||
ItemStack [] payment = inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT);
|
||||
|
||||
return test.tryAddStacksCopy(payment, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true);
|
||||
}
|
||||
|
||||
private int countStorablePayment(int max, ItemStack[] exchange) {
|
||||
|
||||
InventoryAdapter test = inventory.copy();
|
||||
int count = 0;
|
||||
|
||||
for (int i = 0; i < max; i++) {
|
||||
if (test.tryAddStacksCopy(exchange, true))
|
||||
if (test.tryAddStacksCopy(exchange, SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, true))
|
||||
count++;
|
||||
else
|
||||
break;
|
||||
|
||||
@@ -137,6 +137,13 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
return;
|
||||
}
|
||||
|
||||
if (inventory instanceof TradeStation) {
|
||||
if (!((TradeStation)inventory).canReceivePayment()) {
|
||||
setErrorState(EnumErrorCode.NOSPACE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user