mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
Closes #1157
This commit is contained in:
parent
f7bebeec7b
commit
234167f7ad
2 changed files with 39 additions and 9 deletions
|
@ -108,16 +108,16 @@ public class DefaultFarmerBehavior implements IFarmerBehavior {
|
|||
}
|
||||
}
|
||||
|
||||
boolean putSeeds = true;
|
||||
boolean addSeeds = true;
|
||||
if (!farmer.canAddToSeeds(seeds)) {
|
||||
other.addAll(seeds);
|
||||
putSeeds = false;
|
||||
addSeeds = false;
|
||||
}
|
||||
|
||||
if (farmer.canAddToOutput(other)) {
|
||||
farmer.addToOutput(other);
|
||||
|
||||
if (putSeeds) {
|
||||
if (addSeeds) {
|
||||
farmer.addToSeeds(seeds);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -22,6 +23,7 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
public final class StackUtil {
|
||||
|
||||
|
@ -76,7 +78,7 @@ public final class StackUtil {
|
|||
int slotMax = inv.getSlots();
|
||||
int counter = 0;
|
||||
|
||||
for (ItemStack s : stacks) {
|
||||
for (ItemStack s : stacks = merge(stacks)) {
|
||||
for (int i = 0; i < slotMax; i++) {
|
||||
s = inv.insertItem(i, s, true);
|
||||
if (s.isEmpty()) break;
|
||||
|
@ -113,7 +115,7 @@ public final class StackUtil {
|
|||
int slotMax = inv.getSlots();
|
||||
int counter = 0;
|
||||
|
||||
for (ItemStack s : stacks) {
|
||||
for (ItemStack s : stacks = merge(stacks)) {
|
||||
for (int i = 0; i < slotMax; i++) {
|
||||
s = inv.insertItem(i, s, true, fromAutomation);
|
||||
if (s.isEmpty()) break;
|
||||
|
@ -151,7 +153,7 @@ public final class StackUtil {
|
|||
public static boolean canAddAll(ItemStackHandlerAA inv, List<ItemStack> stacks, int slot, int endSlot, boolean fromAutomation) {
|
||||
int counter = 0;
|
||||
|
||||
for (ItemStack s : stacks) {
|
||||
for (ItemStack s : stacks = merge(stacks)) {
|
||||
for (int i = slot; i < endSlot; i++) {
|
||||
s = inv.insertItem(i, s, true, fromAutomation);
|
||||
if (s.isEmpty()) break;
|
||||
|
@ -211,7 +213,7 @@ public final class StackUtil {
|
|||
*/
|
||||
public static ItemStack shrinkForContainer(ItemStack s, int i) {
|
||||
s.shrink(i);
|
||||
if(s.isEmpty()) return s.getItem().getContainerItem(s);
|
||||
if (s.isEmpty()) return s.getItem().getContainerItem(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -246,4 +248,32 @@ public final class StackUtil {
|
|||
return remain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines every stack in the given list into larger stacks when possible.
|
||||
*/
|
||||
public static List<ItemStack> merge(List<ItemStack> stacks) {
|
||||
if (stacks.isEmpty()) return stacks;
|
||||
|
||||
ItemStack[] array = stacks.toArray(new ItemStack[0]);
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
|
||||
while (!array[array.length - 1].isEmpty()) {
|
||||
ItemStack merged = ItemStack.EMPTY;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
ItemStack stack = array[i];
|
||||
if (merged.isEmpty()) {
|
||||
merged = stack.copy();
|
||||
array[i] = ItemStack.EMPTY;
|
||||
} else if (ItemHandlerHelper.canItemStacksStack(merged, stack)) {
|
||||
merged.grow(stack.getCount());
|
||||
array[i] = ItemStack.EMPTY;
|
||||
} else break;
|
||||
}
|
||||
list.add(merged);
|
||||
merged = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue