Requested items and fluids go in immediately, fix crafting monitor not respecting redstone mode.
This commit is contained in:
@@ -15,20 +15,24 @@ class Crafting {
|
||||
private static final String NBT_PATTERN = "Pattern";
|
||||
private static final String NBT_TOOK = "Took";
|
||||
private static final String NBT_TO_EXTRACT = "ToExtract";
|
||||
private static final String NBT_ROOT = "Root";
|
||||
|
||||
private ICraftingPattern pattern;
|
||||
private NonNullList<ItemStack> took;
|
||||
private IStackList<ItemStack> toExtract;
|
||||
private boolean root;
|
||||
|
||||
public Crafting(ICraftingPattern pattern, NonNullList<ItemStack> took, IStackList<ItemStack> toExtract) {
|
||||
public Crafting(ICraftingPattern pattern, NonNullList<ItemStack> took, IStackList<ItemStack> toExtract, boolean root) {
|
||||
this.pattern = pattern;
|
||||
this.took = took;
|
||||
this.toExtract = toExtract;
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public Crafting(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
|
||||
this.pattern = CraftingTask.readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world());
|
||||
this.toExtract = CraftingTask.readItemStackList(tag.getTagList(NBT_TO_EXTRACT, Constants.NBT.TAG_COMPOUND));
|
||||
this.root = tag.getBoolean(NBT_ROOT);
|
||||
|
||||
this.took = NonNullList.create();
|
||||
|
||||
@@ -41,6 +45,10 @@ class Crafting {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public ICraftingPattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
@@ -58,6 +66,7 @@ class Crafting {
|
||||
|
||||
tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern));
|
||||
tag.setTag(NBT_TO_EXTRACT, CraftingTask.writeItemStackList(toExtract));
|
||||
tag.setBoolean(NBT_ROOT, root);
|
||||
|
||||
NBTTagList tookList = new NBTTagList();
|
||||
for (ItemStack took : this.took) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFactoryFl
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFactoryItem;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFluid;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItem;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -95,6 +96,12 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
|
||||
public CraftingTask(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
|
||||
OneSixMigrationHelper.removalHook();
|
||||
|
||||
if (!tag.hasKey(NBT_INTERNAL_STORAGE)) {
|
||||
throw new CraftingTaskReadException("Couldn't read crafting task from before RS v1.6.4, skipping...");
|
||||
}
|
||||
|
||||
this.network = network;
|
||||
|
||||
this.requested = API.instance().createCraftingRequestInfo(tag.getCompoundTag(NBT_REQUESTED));
|
||||
@@ -160,7 +167,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static NBTTagList writeItemStackList(IStackList<ItemStack> stacks) {
|
||||
static NBTTagList writeItemStackList(IStackList<ItemStack> stacks) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (ItemStack stack : stacks.getStacks()) {
|
||||
@@ -170,7 +177,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IStackList<ItemStack> readItemStackList(NBTTagList list) throws CraftingTaskReadException {
|
||||
static IStackList<ItemStack> readItemStackList(NBTTagList list) throws CraftingTaskReadException {
|
||||
IStackList<ItemStack> stacks = API.instance().createItemStackList();
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
@@ -186,7 +193,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static NBTTagList writeFluidStackList(IStackList<FluidStack> stacks) {
|
||||
static NBTTagList writeFluidStackList(IStackList<FluidStack> stacks) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (FluidStack stack : stacks.getStacks()) {
|
||||
@@ -196,7 +203,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static IStackList<FluidStack> readFluidStackList(NBTTagList list) throws CraftingTaskReadException {
|
||||
static IStackList<FluidStack> readFluidStackList(NBTTagList list) throws CraftingTaskReadException {
|
||||
IStackList<FluidStack> stacks = API.instance().createFluidStackList();
|
||||
|
||||
for (int i = 0; i < list.tagCount(); ++i) {
|
||||
@@ -240,7 +247,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
ICraftingPatternChain patternChain = patternChainList.getChain(pattern);
|
||||
|
||||
while (qty > 0) {
|
||||
ICraftingTaskError result = calculateInternal(storage, fluidStorage, results, fluidResults, patternChainList, patternChain.current());
|
||||
ICraftingTaskError result = calculateInternal(storage, fluidStorage, results, fluidResults, patternChainList, patternChain.current(), true);
|
||||
|
||||
if (result != null) {
|
||||
return result;
|
||||
@@ -269,7 +276,8 @@ public class CraftingTask implements ICraftingTask {
|
||||
IStackList<ItemStack> results,
|
||||
IStackList<FluidStack> fluidResults,
|
||||
ICraftingPatternChainList patternChainList,
|
||||
ICraftingPattern pattern) {
|
||||
ICraftingPattern pattern,
|
||||
boolean root) {
|
||||
|
||||
if (System.currentTimeMillis() - calculationStarted > CALCULATION_TIMEOUT_MS) {
|
||||
return new CraftingTaskError(CraftingTaskErrorType.TOO_COMPLEX);
|
||||
@@ -361,7 +369,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
ICraftingPatternChain subPatternChain = patternChainList.getChain(subPattern);
|
||||
|
||||
while ((fromSelf == null ? 0 : fromSelf.getCount()) < remaining) {
|
||||
ICraftingTaskError result = calculateInternal(mutatedStorage, mutatedFluidStorage, results, fluidResults, patternChainList, subPatternChain.current());
|
||||
ICraftingTaskError result = calculateInternal(mutatedStorage, mutatedFluidStorage, results, fluidResults, patternChainList, subPatternChain.current(), false);
|
||||
|
||||
if (result != null) {
|
||||
return result;
|
||||
@@ -428,7 +436,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
ICraftingPatternChain subPatternChain = patternChainList.getChain(subPattern);
|
||||
|
||||
while ((fromSelf == null ? 0 : fromSelf.amount) < remaining) {
|
||||
ICraftingTaskError result = calculateInternal(mutatedStorage, mutatedFluidStorage, results, fluidResults, patternChainList, subPatternChain.current());
|
||||
ICraftingTaskError result = calculateInternal(mutatedStorage, mutatedFluidStorage, results, fluidResults, patternChainList, subPatternChain.current(), false);
|
||||
|
||||
if (result != null) {
|
||||
return result;
|
||||
@@ -475,13 +483,13 @@ public class CraftingTask implements ICraftingTask {
|
||||
fluidsToReceive.add(output);
|
||||
}
|
||||
|
||||
processing.add(new Processing(pattern, itemsToReceive, fluidsToReceive, new ArrayList<>(itemsToExtract.getStacks()), new ArrayList<>(fluidsToExtract.getStacks())));
|
||||
processing.add(new Processing(pattern, itemsToReceive, fluidsToReceive, new ArrayList<>(itemsToExtract.getStacks()), new ArrayList<>(fluidsToExtract.getStacks()), root));
|
||||
} else {
|
||||
if (!fluidsToExtract.isEmpty()) {
|
||||
throw new IllegalStateException("Cannot extract fluids in normal pattern!");
|
||||
}
|
||||
|
||||
crafting.add(new Crafting(pattern, took, itemsToExtract));
|
||||
crafting.add(new Crafting(pattern, took, itemsToExtract, root));
|
||||
|
||||
results.add(pattern.getOutput(took));
|
||||
|
||||
@@ -585,11 +593,28 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
|
||||
ItemStack output = c.getPattern().getOutput(c.getTook());
|
||||
|
||||
if (!c.isRoot()) {
|
||||
this.internalStorage.insert(output, output.getCount(), Action.PERFORM);
|
||||
|
||||
for (ItemStack byp : c.getPattern().getByproducts(c.getTook())) {
|
||||
this.internalStorage.insert(byp, byp.getCount(), Action.PERFORM);
|
||||
}
|
||||
} else {
|
||||
ItemStack remainder = this.network.insertItem(output, output.getCount(), Action.PERFORM);
|
||||
|
||||
if (remainder != null) {
|
||||
this.internalStorage.insert(remainder, remainder.getCount(), Action.PERFORM);
|
||||
}
|
||||
|
||||
for (ItemStack byp : c.getPattern().getByproducts(c.getTook())) {
|
||||
remainder = this.network.insertItem(byp, byp.getCount(), Action.PERFORM);
|
||||
|
||||
if (remainder != null) {
|
||||
this.internalStorage.insert(remainder, remainder.getCount(), Action.PERFORM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it.remove();
|
||||
|
||||
@@ -824,7 +849,15 @@ public class CraftingTask implements ICraftingTask {
|
||||
p.setState(ProcessingState.PROCESSED);
|
||||
}
|
||||
|
||||
if (!p.isRoot()) {
|
||||
internalStorage.insert(stack, needed, Action.PERFORM);
|
||||
} else {
|
||||
ItemStack remainder = network.insertItem(stack, needed, Action.PERFORM);
|
||||
|
||||
if (remainder != null) {
|
||||
internalStorage.insert(stack, needed, Action.PERFORM);
|
||||
}
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
@@ -859,7 +892,15 @@ public class CraftingTask implements ICraftingTask {
|
||||
p.setState(ProcessingState.PROCESSED);
|
||||
}
|
||||
|
||||
if (!p.isRoot()) {
|
||||
internalFluidStorage.insert(stack, needed, Action.PERFORM);
|
||||
} else {
|
||||
FluidStack remainder = network.insertFluid(stack, needed, Action.PERFORM);
|
||||
|
||||
if (remainder != null) {
|
||||
internalFluidStorage.insert(stack, needed, Action.PERFORM);
|
||||
}
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
|
||||
@@ -21,6 +21,7 @@ class Processing {
|
||||
private static final String NBT_ITEMS_TO_PUT = "ItemsToPut";
|
||||
private static final String NBT_FLUIDS_TO_PUT = "FluidsToPut";
|
||||
private static final String NBT_STATE = "State";
|
||||
private static final String NBT_ROOT = "Root";
|
||||
|
||||
private ICraftingPattern pattern;
|
||||
private IStackList<ItemStack> itemsToReceive;
|
||||
@@ -28,19 +29,22 @@ class Processing {
|
||||
private ArrayList<ItemStack> itemsToPut;
|
||||
private ArrayList<FluidStack> fluidsToPut;
|
||||
private ProcessingState state = ProcessingState.READY;
|
||||
private boolean root;
|
||||
|
||||
public Processing(ICraftingPattern pattern, IStackList<ItemStack> itemsToReceive, IStackList<FluidStack> fluidsToReceive, ArrayList<ItemStack> itemsToPut, ArrayList<FluidStack> fluidsToPut) {
|
||||
public Processing(ICraftingPattern pattern, IStackList<ItemStack> itemsToReceive, IStackList<FluidStack> fluidsToReceive, ArrayList<ItemStack> itemsToPut, ArrayList<FluidStack> fluidsToPut, boolean root) {
|
||||
this.pattern = pattern;
|
||||
this.itemsToReceive = itemsToReceive;
|
||||
this.fluidsToReceive = fluidsToReceive;
|
||||
this.itemsToPut = itemsToPut;
|
||||
this.fluidsToPut = fluidsToPut;
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public Processing(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
|
||||
this.pattern = CraftingTask.readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world());
|
||||
this.itemsToReceive = CraftingTask.readItemStackList(tag.getTagList(NBT_ITEMS_TO_RECEIVE, Constants.NBT.TAG_COMPOUND));
|
||||
this.fluidsToReceive = CraftingTask.readFluidStackList(tag.getTagList(NBT_FLUIDS_TO_RECEIVE, Constants.NBT.TAG_COMPOUND));
|
||||
this.root = tag.getBoolean(NBT_ROOT);
|
||||
|
||||
this.itemsToPut = new ArrayList<>();
|
||||
|
||||
@@ -99,12 +103,17 @@ class Processing {
|
||||
return state;
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNbt() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern));
|
||||
tag.setTag(NBT_ITEMS_TO_RECEIVE, CraftingTask.writeItemStackList(itemsToReceive));
|
||||
tag.setTag(NBT_FLUIDS_TO_RECEIVE, CraftingTask.writeFluidStackList(fluidsToReceive));
|
||||
tag.setBoolean(NBT_ROOT, root);
|
||||
|
||||
NBTTagList itemsToPutList = new NBTTagList();
|
||||
for (ItemStack stack : this.itemsToPut) {
|
||||
|
||||
@@ -158,6 +158,10 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
}
|
||||
|
||||
public List<ICraftingMonitorElement> getElements() {
|
||||
if (!craftingMonitor.isActive()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
IGridTab tab = getCurrentTab();
|
||||
|
||||
if (tab == null) {
|
||||
@@ -243,14 +247,18 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
|
||||
@Override
|
||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
||||
if (craftingMonitor.isActive()) {
|
||||
tabs.drawBackground(x, y - tabs.getHeight());
|
||||
}
|
||||
|
||||
bindTexture("gui/crafting_preview.png");
|
||||
|
||||
drawTexture(x, y, 0, 0, screenWidth, screenHeight);
|
||||
|
||||
if (craftingMonitor.isActive()) {
|
||||
tabs.drawForeground(x, y - tabs.getHeight(), mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawForeground(int mouseX, int mouseY) {
|
||||
|
||||
@@ -320,7 +320,7 @@ public class ProxyCommon {
|
||||
OneSixMigrationHelper.removalHook();
|
||||
|
||||
for (RegistryEvent.MissingMappings.Mapping<Item> missing : e.getMappings()) {
|
||||
if (missing.key.getNamespace().equals(RS.ID) && (missing.key.getPath().equals("wrench") || missing.key.getPath().equals("solderer"))) {
|
||||
if (missing.key.getNamespace().equals(RS.ID) && missing.key.getPath().equals("solderer")) {
|
||||
missing.ignore();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user