Minor fixes to autocrafting, fixes #1501

This commit is contained in:
raoulvdberge
2017-12-01 14:51:50 +01:00
parent 4d1a3cadd6
commit 571c2b18af
5 changed files with 25 additions and 3 deletions

View File

@@ -106,7 +106,7 @@ public abstract class CraftingStep implements ICraftingStep {
@Override
public List<ItemStack> getInputs() {
return pattern.getInputs().stream().filter(Objects::nonNull).collect(Collectors.toList());
return pattern.getInputs().stream().filter(Objects::nonNull).filter(s -> !s.isEmpty()).collect(Collectors.toList());
}
@Override

View File

@@ -38,7 +38,7 @@ public class CraftingStepCraft extends CraftingStep {
@Override
public List<ItemStack> getInputs() {
return inputs == null ? super.getInputs() : inputs.stream().filter(Objects::nonNull).collect(Collectors.toList());
return inputs == null ? super.getInputs() : inputs.stream().filter(Objects::nonNull).filter(s -> !s.isEmpty()).collect(Collectors.toList());
}
@Override

View File

@@ -22,6 +22,10 @@ public class StackListItem implements IStackList<ItemStack> {
@Override
public void add(@Nonnull ItemStack stack, int size) {
if (stack.isEmpty() || size <= 0) {
return;
}
for (ItemStack otherStack : stacks.get(stack.getItem())) {
if (API.instance().getComparer().isEqualNoQuantity(otherStack, stack)) {
if ((long) otherStack.getCount() + (long) size > Integer.MAX_VALUE) {
@@ -34,7 +38,7 @@ public class StackListItem implements IStackList<ItemStack> {
}
}
stacks.put(stack.getItem(), size == 0 ? stack.copy() : ItemHandlerHelper.copyStackWithSize(stack, size));
stacks.put(stack.getItem(), ItemHandlerHelper.copyStackWithSize(stack, size));
}
@Override

View File

@@ -38,7 +38,9 @@ public class StackListItemOredicted implements IStackList<ItemStack> {
@Override
public void add(@Nonnull ItemStack stack, int size) {
underlyingList.add(stack, size);
ItemStack internalStack = underlyingList.get(stack);
if (internalStack != null && internalStack.getCount() == stack.getCount()) {
for (int id : OreDictionary.getOreIDs(internalStack)) {
stacks.put(id, internalStack);
@@ -49,10 +51,13 @@ public class StackListItemOredicted implements IStackList<ItemStack> {
@Override
public boolean remove(@Nonnull ItemStack stack, int size) {
boolean rvalue = underlyingList.remove(stack, size);
if (underlyingList.needsCleanup) {
touchedIds.addAll(Arrays.stream(OreDictionary.getOreIDs(stack)).boxed().collect(Collectors.toList()));
clean();
}
return rvalue;
}
@@ -62,10 +67,12 @@ public class StackListItemOredicted implements IStackList<ItemStack> {
// When the underlying list empties the stack the reference will become empty, thus we need to copy before hand
ItemStack original = stack.copy();
boolean rvalue = underlyingList.trackedRemove(stack, size);
if (underlyingList.needsCleanup) {
touchedIds.addAll(Arrays.stream(OreDictionary.getOreIDs(original)).boxed().collect(Collectors.toList()));
clean();
}
return rvalue;
}
@@ -85,17 +92,23 @@ public class StackListItemOredicted implements IStackList<ItemStack> {
public ItemStack get(@Nonnull ItemStack stack, int flags) {
// Check the underlying list but don't do oredict things for exact match
ItemStack exact = underlyingList.get(stack, flags & ~IComparer.COMPARE_OREDICT);
if (exact == null) {
if ((flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT) {
int[] ids = OreDictionary.getOreIDs(stack);
for (int id : ids) {
List<ItemStack> stacks = this.stacks.get(id);
if (stacks != null && !stacks.isEmpty()) {
int i = 0;
ItemStack returnStack = stacks.get(i++);
while (returnStack.isEmpty() && i < stacks.size()) {
returnStack = stacks.get(i++);
}
if (!returnStack.isEmpty()) {
return returnStack;
}
@@ -103,6 +116,7 @@ public class StackListItemOredicted implements IStackList<ItemStack> {
}
}
}
return exact;
}
@@ -112,6 +126,7 @@ public class StackListItemOredicted implements IStackList<ItemStack> {
if (underlyingList.needsCleanup) {
clean();
}
return underlyingList.get(hash);
}
@@ -158,9 +173,11 @@ public class StackListItemOredicted implements IStackList<ItemStack> {
public IStackList<ItemStack> copy() {
StackListItemOredicted newList = new StackListItemOredicted();
newList.underlyingList = (StackListItem) this.underlyingList.copy();
for (Map.Entry<Integer, ItemStack> entry : this.stacks.entries()) {
newList.stacks.put(entry.getKey(), entry.getValue());
}
return newList;
}