Processing patterns now use the order of items/fluids specified in the pattern.
Cherry picked from bb44bf1633f4986a9400a7eaa55e5d0e96e9989d
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.refinedmods.refinedstorage.api.autocrafting;
|
||||
|
||||
import com.refinedmods.refinedstorage.api.util.Action;
|
||||
import com.refinedmods.refinedstorage.api.util.StackListEntry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -152,7 +151,7 @@ public interface ICraftingPatternContainer {
|
||||
* @param action action to perform
|
||||
* @return whether insertion was successful
|
||||
*/
|
||||
default boolean insertItemsIntoInventory(Collection<StackListEntry<ItemStack>> toInsert, Action action) {
|
||||
default boolean insertItemsIntoInventory(Collection<ItemStack> toInsert, Action action) {
|
||||
IItemHandler dest = getConnectedInventory();
|
||||
|
||||
|
||||
@@ -164,11 +163,10 @@ public interface ICraftingPatternContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
Deque<StackListEntry<ItemStack>> stacks = new ArrayDeque<>(toInsert);
|
||||
Deque<ItemStack> stacks = new ArrayDeque<>(toInsert);
|
||||
|
||||
StackListEntry<ItemStack> currentEntry = stacks.poll();
|
||||
|
||||
ItemStack current = currentEntry != null ? currentEntry.getStack() : null;
|
||||
ItemStack current = stacks.poll();
|
||||
|
||||
List<Integer> availableSlots = IntStream.range(0, dest.getSlots()).boxed().collect(Collectors.toList());
|
||||
|
||||
@@ -189,9 +187,8 @@ public interface ICraftingPatternContainer {
|
||||
}
|
||||
|
||||
if (remainder.isEmpty()) { // If we inserted successfully, get a next stack.
|
||||
currentEntry = stacks.poll();
|
||||
current = stacks.poll();
|
||||
|
||||
current = currentEntry != null ? currentEntry.getStack() : null;
|
||||
} else if (current.getCount() == remainder.getCount()) { // If we didn't insert anything over ALL these slots, stop here.
|
||||
break;
|
||||
} else { // If we didn't insert all, continue with other slots and use our remainder.
|
||||
@@ -215,7 +212,7 @@ public interface ICraftingPatternContainer {
|
||||
* @param action action to perform
|
||||
* @return whether insertion was successful
|
||||
*/
|
||||
default boolean insertFluidsIntoInventory(Collection<StackListEntry<FluidStack>> toInsert, Action action) {
|
||||
default boolean insertFluidsIntoInventory(Collection<FluidStack> toInsert, Action action) {
|
||||
IFluidHandler dest = getConnectedFluidInventory();
|
||||
|
||||
if (toInsert.isEmpty()) {
|
||||
@@ -226,12 +223,12 @@ public interface ICraftingPatternContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (StackListEntry<FluidStack> entry : toInsert) {
|
||||
int filled = dest.fill(entry.getStack(), action == Action.SIMULATE ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE);
|
||||
for (FluidStack stack : toInsert) {
|
||||
int filled = dest.fill(stack, action == Action.SIMULATE ? IFluidHandler.FluidAction.SIMULATE : IFluidHandler.FluidAction.EXECUTE);
|
||||
|
||||
if (filled != entry.getStack().getAmount()) {
|
||||
if (filled != stack.getAmount()) {
|
||||
if (action == Action.PERFORM) {
|
||||
LogManager.getLogger().warn("Inventory unexpectedly didn't accept all of {}, the remainder has been voided!", entry.getStack().getTranslationKey());
|
||||
LogManager.getLogger().warn("Inventory unexpectedly didn't accept all of {}, the remainder has been voided!", stack.getTranslationKey());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@@ -6,7 +6,6 @@ import com.refinedmods.refinedstorage.api.util.Action;
|
||||
import com.refinedmods.refinedstorage.api.util.IComparer;
|
||||
import com.refinedmods.refinedstorage.api.util.IStackList;
|
||||
import com.refinedmods.refinedstorage.api.util.StackListEntry;
|
||||
import com.refinedmods.refinedstorage.apiimpl.API;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -19,15 +18,15 @@ public final class IoUtil {
|
||||
private IoUtil() {
|
||||
}
|
||||
|
||||
public static IStackList<ItemStack> extractFromInternalItemStorage(IStackList<ItemStack> list, IStorageDisk<ItemStack> storage, Action action) {
|
||||
IStackList<ItemStack> extracted = API.instance().createItemStackList();
|
||||
public static List<ItemStack> extractFromInternalItemStorage(List<ItemStack> list, IStorageDisk<ItemStack> storage, Action action) {
|
||||
List<ItemStack> extracted = new ArrayList<>();
|
||||
|
||||
for (StackListEntry<ItemStack> entry : list.getStacks()) {
|
||||
ItemStack result = storage.extract(entry.getStack(), entry.getStack().getCount(), DEFAULT_EXTRACT_FLAGS, action);
|
||||
for (ItemStack stack : list) {
|
||||
ItemStack result = storage.extract(stack, stack.getCount(), DEFAULT_EXTRACT_FLAGS, action);
|
||||
|
||||
if (result.isEmpty() || result.getCount() != entry.getStack().getCount()) {
|
||||
if (result.isEmpty() || result.getCount() != stack.getCount()) {
|
||||
if (action == Action.PERFORM) {
|
||||
throw new IllegalStateException("The internal crafting inventory reported that " + entry.getStack() + " was available but we got " + result);
|
||||
throw new IllegalStateException("The internal crafting inventory reported that " + stack + " was available but we got " + result);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -39,15 +38,15 @@ public final class IoUtil {
|
||||
return extracted;
|
||||
}
|
||||
|
||||
public static IStackList<FluidStack> extractFromInternalFluidStorage(IStackList<FluidStack> list, IStorageDisk<FluidStack> storage, Action action) {
|
||||
IStackList<FluidStack> extracted = API.instance().createFluidStackList();
|
||||
public static List<FluidStack> extractFromInternalFluidStorage(List<FluidStack> list, IStorageDisk<FluidStack> storage, Action action) {
|
||||
List<FluidStack> extracted = new ArrayList<>();
|
||||
|
||||
for (StackListEntry<FluidStack> entry : list.getStacks()) {
|
||||
FluidStack result = storage.extract(entry.getStack(), entry.getStack().getAmount(), DEFAULT_EXTRACT_FLAGS, action);
|
||||
for (FluidStack stack : list) {
|
||||
FluidStack result = storage.extract(stack, stack.getAmount(), DEFAULT_EXTRACT_FLAGS, action);
|
||||
|
||||
if (result.isEmpty() || result.getAmount() != entry.getStack().getAmount()) {
|
||||
if (result.isEmpty() || result.getAmount() != stack.getAmount()) {
|
||||
if (action == Action.PERFORM) {
|
||||
throw new IllegalStateException("The internal crafting inventory reported that " + entry.getStack() + " was available but we got " + result);
|
||||
throw new IllegalStateException("The internal crafting inventory reported that " + stack + " was available but we got " + result);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@@ -11,12 +11,10 @@ import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class NodeRequirements {
|
||||
private static final String NBT_ITEMS_TO_USE = "ItemsToUse";
|
||||
@@ -32,9 +30,9 @@ public class NodeRequirements {
|
||||
private final Map<Integer, Integer> fluidsNeededPerCraft = new LinkedHashMap<>();
|
||||
|
||||
@Nullable
|
||||
private IStackList<ItemStack> cachedSimulatedItemRequirementSet = null;
|
||||
private List<ItemStack> cachedSimulatedItemRequirementSet = null;
|
||||
@Nullable
|
||||
private IStackList<FluidStack> cachedSimulatedFluidRequirementSet = null;
|
||||
private List<FluidStack> cachedSimulatedFluidRequirementSet = null;
|
||||
|
||||
public void addItemRequirement(int ingredientNumber, ItemStack stack, int size, int perCraft) {
|
||||
if (!itemsNeededPerCraft.containsKey(ingredientNumber)) {
|
||||
@@ -56,13 +54,13 @@ public class NodeRequirements {
|
||||
cachedSimulatedFluidRequirementSet = null;
|
||||
}
|
||||
|
||||
public IStackList<ItemStack> getSingleItemRequirementSet(boolean simulate) {
|
||||
IStackList<ItemStack> cached = cachedSimulatedItemRequirementSet;
|
||||
public List<ItemStack> getSingleItemRequirementSet(boolean simulate) {
|
||||
List<ItemStack> cached = cachedSimulatedItemRequirementSet;
|
||||
if (simulate && cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
IStackList<ItemStack> toReturn = API.instance().createItemStackList();
|
||||
List<ItemStack> toReturn = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < itemRequirements.size(); i++) {
|
||||
int needed = itemsNeededPerCraft.get(i);
|
||||
@@ -78,7 +76,7 @@ public class NodeRequirements {
|
||||
itemRequirements.get(i).remove(toUse, needed);
|
||||
}
|
||||
|
||||
toReturn.add(toUse, needed);
|
||||
toReturn.add(ItemHandlerHelper.copyStackWithSize(toUse, needed));
|
||||
|
||||
needed = 0;
|
||||
} else {
|
||||
@@ -101,13 +99,13 @@ public class NodeRequirements {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public IStackList<FluidStack> getSingleFluidRequirementSet(boolean simulate) {
|
||||
IStackList<FluidStack> cached = cachedSimulatedFluidRequirementSet;
|
||||
public List<FluidStack> getSingleFluidRequirementSet(boolean simulate) {
|
||||
List<FluidStack> cached = cachedSimulatedFluidRequirementSet;
|
||||
if (simulate && cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
IStackList<FluidStack> toReturn = API.instance().createFluidStackList();
|
||||
List<FluidStack> toReturn = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < fluidRequirements.size(); i++) {
|
||||
int needed = fluidsNeededPerCraft.get(i);
|
||||
@@ -123,7 +121,9 @@ public class NodeRequirements {
|
||||
fluidRequirements.get(i).remove(toUse, needed);
|
||||
}
|
||||
|
||||
toReturn.add(toUse, needed);
|
||||
FluidStack stack = toUse.copy();
|
||||
stack.setAmount(needed);
|
||||
toReturn.add(stack);
|
||||
|
||||
needed = 0;
|
||||
} else {
|
||||
|
@@ -11,11 +11,15 @@ import com.refinedmods.refinedstorage.api.util.StackListEntry;
|
||||
import com.refinedmods.refinedstorage.apiimpl.API;
|
||||
import com.refinedmods.refinedstorage.apiimpl.autocrafting.task.v6.IoUtil;
|
||||
import com.refinedmods.refinedstorage.apiimpl.autocrafting.task.v6.SerializationUtil;
|
||||
import com.refinedmods.refinedstorage.apiimpl.util.FluidStackList;
|
||||
import com.refinedmods.refinedstorage.apiimpl.util.ItemStackList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProcessingNode extends Node {
|
||||
private static final String NBT_ITEMS_RECEIVED = "ItemsReceived";
|
||||
private static final String NBT_FLUIDS_RECEIVED = "FluidsReceived";
|
||||
@@ -117,8 +121,8 @@ public class ProcessingNode extends Node {
|
||||
|
||||
boolean hasAllRequirements = false;
|
||||
|
||||
IStackList<ItemStack> extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(true), internalStorage, Action.SIMULATE);
|
||||
IStackList<FluidStack> extractedFluids = null;
|
||||
List<ItemStack> extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(true), internalStorage, Action.SIMULATE);
|
||||
List<FluidStack> extractedFluids = null;
|
||||
if (extractedItems != null) {
|
||||
extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(true), internalFluidStorage, Action.SIMULATE);
|
||||
if (extractedFluids != null) {
|
||||
@@ -128,9 +132,9 @@ public class ProcessingNode extends Node {
|
||||
|
||||
boolean canInsertFullAmount = false;
|
||||
if (hasAllRequirements) {
|
||||
canInsertFullAmount = container.insertItemsIntoInventory(extractedItems.getStacks(), Action.SIMULATE);
|
||||
canInsertFullAmount = container.insertItemsIntoInventory(extractedItems, Action.SIMULATE);
|
||||
if (canInsertFullAmount) {
|
||||
canInsertFullAmount = container.insertFluidsIntoInventory(extractedFluids.getStacks(), Action.SIMULATE);
|
||||
canInsertFullAmount = container.insertFluidsIntoInventory(extractedFluids, Action.SIMULATE);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
@@ -151,8 +155,8 @@ public class ProcessingNode extends Node {
|
||||
extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(false), internalStorage, Action.PERFORM);
|
||||
extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(false), internalFluidStorage, Action.PERFORM);
|
||||
|
||||
container.insertItemsIntoInventory(extractedItems.getStacks(), Action.PERFORM);
|
||||
container.insertFluidsIntoInventory(extractedFluids.getStacks(), Action.PERFORM);
|
||||
container.insertItemsIntoInventory(extractedItems, Action.PERFORM);
|
||||
container.insertFluidsIntoInventory(extractedFluids, Action.PERFORM);
|
||||
|
||||
next();
|
||||
|
||||
@@ -249,8 +253,8 @@ public class ProcessingNode extends Node {
|
||||
public void onCalculationFinished() {
|
||||
super.onCalculationFinished();
|
||||
|
||||
this.singleItemSetToRequire = requirements.getSingleItemRequirementSet(true);
|
||||
this.singleFluidSetToRequire = requirements.getSingleFluidRequirementSet(true);
|
||||
this.singleItemSetToRequire = new ItemStackList(requirements.getSingleItemRequirementSet(true));
|
||||
this.singleFluidSetToRequire = new FluidStackList(requirements.getSingleFluidRequirementSet(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -19,6 +19,15 @@ public class FluidStackList implements IStackList<FluidStack> {
|
||||
private final ArrayListMultimap<Fluid, StackListEntry<FluidStack>> stacks = ArrayListMultimap.create();
|
||||
private final Map<UUID, FluidStack> index = new HashMap<>();
|
||||
|
||||
public FluidStackList() {
|
||||
}
|
||||
|
||||
public FluidStackList(Iterable<FluidStack> stacks) {
|
||||
for (FluidStack stack : stacks) {
|
||||
add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackListResult<FluidStack> add(@Nonnull FluidStack stack, int size) {
|
||||
if (stack.isEmpty() || size <= 0) {
|
||||
|
@@ -20,6 +20,15 @@ public class ItemStackList implements IStackList<ItemStack> {
|
||||
private final ArrayListMultimap<Item, StackListEntry<ItemStack>> stacks = ArrayListMultimap.create();
|
||||
private final Map<UUID, ItemStack> index = new HashMap<>();
|
||||
|
||||
public ItemStackList() {
|
||||
}
|
||||
|
||||
public ItemStackList(Iterable<ItemStack> stacks) {
|
||||
for (ItemStack stack : stacks) {
|
||||
add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackListResult<ItemStack> add(@Nonnull ItemStack stack, int size) {
|
||||
if (stack.isEmpty() || size <= 0) {
|
||||
|
Reference in New Issue
Block a user