Requested items and fluids go in immediately, fix crafting monitor not respecting redstone mode.

This commit is contained in:
raoulvdberge
2018-08-23 16:59:39 +02:00
parent e77f038b61
commit 129f93549b
5 changed files with 87 additions and 20 deletions

View File

@@ -15,20 +15,24 @@ class Crafting {
private static final String NBT_PATTERN = "Pattern"; private static final String NBT_PATTERN = "Pattern";
private static final String NBT_TOOK = "Took"; private static final String NBT_TOOK = "Took";
private static final String NBT_TO_EXTRACT = "ToExtract"; private static final String NBT_TO_EXTRACT = "ToExtract";
private static final String NBT_ROOT = "Root";
private ICraftingPattern pattern; private ICraftingPattern pattern;
private NonNullList<ItemStack> took; private NonNullList<ItemStack> took;
private IStackList<ItemStack> toExtract; 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.pattern = pattern;
this.took = took; this.took = took;
this.toExtract = toExtract; this.toExtract = toExtract;
this.root = root;
} }
public Crafting(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException { public Crafting(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
this.pattern = CraftingTask.readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world()); this.pattern = CraftingTask.readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world());
this.toExtract = CraftingTask.readItemStackList(tag.getTagList(NBT_TO_EXTRACT, Constants.NBT.TAG_COMPOUND)); this.toExtract = CraftingTask.readItemStackList(tag.getTagList(NBT_TO_EXTRACT, Constants.NBT.TAG_COMPOUND));
this.root = tag.getBoolean(NBT_ROOT);
this.took = NonNullList.create(); this.took = NonNullList.create();
@@ -41,6 +45,10 @@ class Crafting {
} }
} }
public boolean isRoot() {
return root;
}
public ICraftingPattern getPattern() { public ICraftingPattern getPattern() {
return pattern; return pattern;
} }
@@ -58,6 +66,7 @@ class Crafting {
tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern)); tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern));
tag.setTag(NBT_TO_EXTRACT, CraftingTask.writeItemStackList(toExtract)); tag.setTag(NBT_TO_EXTRACT, CraftingTask.writeItemStackList(toExtract));
tag.setBoolean(NBT_ROOT, root);
NBTTagList tookList = new NBTTagList(); NBTTagList tookList = new NBTTagList();
for (ItemStack took : this.took) { for (ItemStack took : this.took) {

View File

@@ -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.StorageDiskFactoryItem;
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFluid; import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskFluid;
import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItem; import com.raoulvdberge.refinedstorage.apiimpl.storage.disk.StorageDiskItem;
import com.raoulvdberge.refinedstorage.apiimpl.util.OneSixMigrationHelper;
import com.raoulvdberge.refinedstorage.util.StackUtils; import com.raoulvdberge.refinedstorage.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -95,6 +96,12 @@ public class CraftingTask implements ICraftingTask {
} }
public CraftingTask(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException { 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.network = network;
this.requested = API.instance().createCraftingRequestInfo(tag.getCompoundTag(NBT_REQUESTED)); this.requested = API.instance().createCraftingRequestInfo(tag.getCompoundTag(NBT_REQUESTED));
@@ -160,7 +167,7 @@ public class CraftingTask implements ICraftingTask {
return tag; return tag;
} }
public static NBTTagList writeItemStackList(IStackList<ItemStack> stacks) { static NBTTagList writeItemStackList(IStackList<ItemStack> stacks) {
NBTTagList list = new NBTTagList(); NBTTagList list = new NBTTagList();
for (ItemStack stack : stacks.getStacks()) { for (ItemStack stack : stacks.getStacks()) {
@@ -170,7 +177,7 @@ public class CraftingTask implements ICraftingTask {
return list; 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(); IStackList<ItemStack> stacks = API.instance().createItemStackList();
for (int i = 0; i < list.tagCount(); ++i) { for (int i = 0; i < list.tagCount(); ++i) {
@@ -186,7 +193,7 @@ public class CraftingTask implements ICraftingTask {
return stacks; return stacks;
} }
public static NBTTagList writeFluidStackList(IStackList<FluidStack> stacks) { static NBTTagList writeFluidStackList(IStackList<FluidStack> stacks) {
NBTTagList list = new NBTTagList(); NBTTagList list = new NBTTagList();
for (FluidStack stack : stacks.getStacks()) { for (FluidStack stack : stacks.getStacks()) {
@@ -196,7 +203,7 @@ public class CraftingTask implements ICraftingTask {
return list; 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(); IStackList<FluidStack> stacks = API.instance().createFluidStackList();
for (int i = 0; i < list.tagCount(); ++i) { for (int i = 0; i < list.tagCount(); ++i) {
@@ -240,7 +247,7 @@ public class CraftingTask implements ICraftingTask {
ICraftingPatternChain patternChain = patternChainList.getChain(pattern); ICraftingPatternChain patternChain = patternChainList.getChain(pattern);
while (qty > 0) { 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) { if (result != null) {
return result; return result;
@@ -269,7 +276,8 @@ public class CraftingTask implements ICraftingTask {
IStackList<ItemStack> results, IStackList<ItemStack> results,
IStackList<FluidStack> fluidResults, IStackList<FluidStack> fluidResults,
ICraftingPatternChainList patternChainList, ICraftingPatternChainList patternChainList,
ICraftingPattern pattern) { ICraftingPattern pattern,
boolean root) {
if (System.currentTimeMillis() - calculationStarted > CALCULATION_TIMEOUT_MS) { if (System.currentTimeMillis() - calculationStarted > CALCULATION_TIMEOUT_MS) {
return new CraftingTaskError(CraftingTaskErrorType.TOO_COMPLEX); return new CraftingTaskError(CraftingTaskErrorType.TOO_COMPLEX);
@@ -361,7 +369,7 @@ public class CraftingTask implements ICraftingTask {
ICraftingPatternChain subPatternChain = patternChainList.getChain(subPattern); ICraftingPatternChain subPatternChain = patternChainList.getChain(subPattern);
while ((fromSelf == null ? 0 : fromSelf.getCount()) < remaining) { 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) { if (result != null) {
return result; return result;
@@ -428,7 +436,7 @@ public class CraftingTask implements ICraftingTask {
ICraftingPatternChain subPatternChain = patternChainList.getChain(subPattern); ICraftingPatternChain subPatternChain = patternChainList.getChain(subPattern);
while ((fromSelf == null ? 0 : fromSelf.amount) < remaining) { 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) { if (result != null) {
return result; return result;
@@ -475,13 +483,13 @@ public class CraftingTask implements ICraftingTask {
fluidsToReceive.add(output); 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 { } else {
if (!fluidsToExtract.isEmpty()) { if (!fluidsToExtract.isEmpty()) {
throw new IllegalStateException("Cannot extract fluids in normal pattern!"); 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)); results.add(pattern.getOutput(took));
@@ -585,10 +593,27 @@ public class CraftingTask implements ICraftingTask {
} }
ItemStack output = c.getPattern().getOutput(c.getTook()); ItemStack output = c.getPattern().getOutput(c.getTook());
this.internalStorage.insert(output, output.getCount(), Action.PERFORM);
for (ItemStack byp : c.getPattern().getByproducts(c.getTook())) { if (!c.isRoot()) {
this.internalStorage.insert(byp, byp.getCount(), Action.PERFORM); 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(); it.remove();
@@ -824,7 +849,15 @@ public class CraftingTask implements ICraftingTask {
p.setState(ProcessingState.PROCESSED); p.setState(ProcessingState.PROCESSED);
} }
internalStorage.insert(stack, needed, Action.PERFORM); 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) { if (size == 0) {
return 0; return 0;
@@ -859,7 +892,15 @@ public class CraftingTask implements ICraftingTask {
p.setState(ProcessingState.PROCESSED); p.setState(ProcessingState.PROCESSED);
} }
internalFluidStorage.insert(stack, needed, Action.PERFORM); 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) { if (size == 0) {
return 0; return 0;

View File

@@ -21,6 +21,7 @@ class Processing {
private static final String NBT_ITEMS_TO_PUT = "ItemsToPut"; private static final String NBT_ITEMS_TO_PUT = "ItemsToPut";
private static final String NBT_FLUIDS_TO_PUT = "FluidsToPut"; private static final String NBT_FLUIDS_TO_PUT = "FluidsToPut";
private static final String NBT_STATE = "State"; private static final String NBT_STATE = "State";
private static final String NBT_ROOT = "Root";
private ICraftingPattern pattern; private ICraftingPattern pattern;
private IStackList<ItemStack> itemsToReceive; private IStackList<ItemStack> itemsToReceive;
@@ -28,19 +29,22 @@ class Processing {
private ArrayList<ItemStack> itemsToPut; private ArrayList<ItemStack> itemsToPut;
private ArrayList<FluidStack> fluidsToPut; private ArrayList<FluidStack> fluidsToPut;
private ProcessingState state = ProcessingState.READY; 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.pattern = pattern;
this.itemsToReceive = itemsToReceive; this.itemsToReceive = itemsToReceive;
this.fluidsToReceive = fluidsToReceive; this.fluidsToReceive = fluidsToReceive;
this.itemsToPut = itemsToPut; this.itemsToPut = itemsToPut;
this.fluidsToPut = fluidsToPut; this.fluidsToPut = fluidsToPut;
this.root = root;
} }
public Processing(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException { public Processing(INetwork network, NBTTagCompound tag) throws CraftingTaskReadException {
this.pattern = CraftingTask.readPatternFromNbt(tag.getCompoundTag(NBT_PATTERN), network.world()); 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.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.fluidsToReceive = CraftingTask.readFluidStackList(tag.getTagList(NBT_FLUIDS_TO_RECEIVE, Constants.NBT.TAG_COMPOUND));
this.root = tag.getBoolean(NBT_ROOT);
this.itemsToPut = new ArrayList<>(); this.itemsToPut = new ArrayList<>();
@@ -99,12 +103,17 @@ class Processing {
return state; return state;
} }
public boolean isRoot() {
return root;
}
public NBTTagCompound writeToNbt() { public NBTTagCompound writeToNbt() {
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern)); tag.setTag(NBT_PATTERN, CraftingTask.writePatternToNbt(pattern));
tag.setTag(NBT_ITEMS_TO_RECEIVE, CraftingTask.writeItemStackList(itemsToReceive)); tag.setTag(NBT_ITEMS_TO_RECEIVE, CraftingTask.writeItemStackList(itemsToReceive));
tag.setTag(NBT_FLUIDS_TO_RECEIVE, CraftingTask.writeFluidStackList(fluidsToReceive)); tag.setTag(NBT_FLUIDS_TO_RECEIVE, CraftingTask.writeFluidStackList(fluidsToReceive));
tag.setBoolean(NBT_ROOT, root);
NBTTagList itemsToPutList = new NBTTagList(); NBTTagList itemsToPutList = new NBTTagList();
for (ItemStack stack : this.itemsToPut) { for (ItemStack stack : this.itemsToPut) {

View File

@@ -158,6 +158,10 @@ public class GuiCraftingMonitor extends GuiBase {
} }
public List<ICraftingMonitorElement> getElements() { public List<ICraftingMonitorElement> getElements() {
if (!craftingMonitor.isActive()) {
return Collections.emptyList();
}
IGridTab tab = getCurrentTab(); IGridTab tab = getCurrentTab();
if (tab == null) { if (tab == null) {
@@ -243,13 +247,17 @@ public class GuiCraftingMonitor extends GuiBase {
@Override @Override
public void drawBackground(int x, int y, int mouseX, int mouseY) { public void drawBackground(int x, int y, int mouseX, int mouseY) {
tabs.drawBackground(x, y - tabs.getHeight()); if (craftingMonitor.isActive()) {
tabs.drawBackground(x, y - tabs.getHeight());
}
bindTexture("gui/crafting_preview.png"); bindTexture("gui/crafting_preview.png");
drawTexture(x, y, 0, 0, screenWidth, screenHeight); drawTexture(x, y, 0, 0, screenWidth, screenHeight);
tabs.drawForeground(x, y - tabs.getHeight(), mouseX, mouseY); if (craftingMonitor.isActive()) {
tabs.drawForeground(x, y - tabs.getHeight(), mouseX, mouseY);
}
} }
@Override @Override

View File

@@ -320,7 +320,7 @@ public class ProxyCommon {
OneSixMigrationHelper.removalHook(); OneSixMigrationHelper.removalHook();
for (RegistryEvent.MissingMappings.Mapping<Item> missing : e.getMappings()) { 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(); missing.ignore();
} }
} }