Added max crafting task depth

This commit is contained in:
Raoul Van den Berge
2016-09-25 11:31:53 +02:00
parent dd1e20374a
commit 0a89d0318f
12 changed files with 29 additions and 21 deletions

View File

@@ -2,6 +2,7 @@
### 1.0.6 ### 1.0.6
- Added crafting preview screen (way2muchnoise) - Added crafting preview screen (way2muchnoise)
- Added max crafting task depth (raoulvdberge)
### 1.0.5 ### 1.0.5
- Fixed crafting a complex item causes the process to flow off the Crafting Monitor's GUI (raoulvdberge) - Fixed crafting a complex item causes the process to flow off the Crafting Monitor's GUI (raoulvdberge)

View File

@@ -17,10 +17,11 @@ public interface ICraftingTaskFactory {
* Returns a crafting task for a given NBT tag and pattern. * Returns a crafting task for a given NBT tag and pattern.
* *
* @param world the world * @param world the world
* @param depth the depth of the crafting task to create
* @param tag the NBT tag, if this is null it isn't reading from disk but is used for making a task on demand * @param tag the NBT tag, if this is null it isn't reading from disk but is used for making a task on demand
* @param pattern the pattern * @param pattern the pattern
* @return the crafting task * @return the crafting task
*/ */
@Nonnull @Nonnull
ICraftingTask create(World world, @Nullable NBTTagCompound tag, ICraftingPattern pattern); ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern);
} }

View File

@@ -18,6 +18,8 @@ import java.util.List;
* A default implementation for crafting tasks. * A default implementation for crafting tasks.
*/ */
public abstract class CraftingTask implements ICraftingTask { public abstract class CraftingTask implements ICraftingTask {
public static final int MAX_DEPTH = 100;
public static final String NBT_CHILDREN_CREATED = "ChildrenCreated"; public static final String NBT_CHILDREN_CREATED = "ChildrenCreated";
public static final String NBT_SATISFIED = "Satisfied"; public static final String NBT_SATISFIED = "Satisfied";
public static final String NBT_CHECKED = "Checked"; public static final String NBT_CHECKED = "Checked";
@@ -28,6 +30,8 @@ public abstract class CraftingTask implements ICraftingTask {
private static final String NBT_CHILD = "Child"; private static final String NBT_CHILD = "Child";
protected int depth;
protected ICraftingPattern pattern; protected ICraftingPattern pattern;
protected ICraftingTask child; protected ICraftingTask child;
@@ -37,11 +41,12 @@ public abstract class CraftingTask implements ICraftingTask {
protected boolean satisfied[]; protected boolean satisfied[];
protected boolean checked[]; protected boolean checked[];
public CraftingTask(ICraftingPattern pattern) { public CraftingTask(ICraftingPattern pattern, int depth) {
this.pattern = pattern; this.pattern = pattern;
this.childrenCreated = new boolean[pattern.getInputs().size()]; this.childrenCreated = new boolean[pattern.getInputs().size()];
this.satisfied = new boolean[pattern.getInputs().size()]; this.satisfied = new boolean[pattern.getInputs().size()];
this.checked = new boolean[pattern.getInputs().size()]; this.checked = new boolean[pattern.getInputs().size()];
this.depth = depth;
} }
@Override @Override
@@ -82,11 +87,11 @@ public abstract class CraftingTask implements ICraftingTask {
} }
protected void tryCreateChild(INetworkMaster network, int i) { protected void tryCreateChild(INetworkMaster network, int i) {
if (!childrenCreated[i]) { if (!childrenCreated[i] && depth + 1 < MAX_DEPTH) {
ICraftingPattern pattern = NetworkUtils.getPattern(network, this.pattern.getInputs().get(i)); ICraftingPattern pattern = NetworkUtils.getPattern(network, this.pattern.getInputs().get(i));
if (pattern != null) { if (pattern != null) {
child = NetworkUtils.createCraftingTask(network, pattern); child = NetworkUtils.createCraftingTask(network, depth + 1, pattern);
childrenCreated[i] = true; childrenCreated[i] = true;
} }
@@ -143,7 +148,7 @@ public abstract class CraftingTask implements ICraftingTask {
public void readChildNBT(World world, NBTTagCompound tag) { public void readChildNBT(World world, NBTTagCompound tag) {
if (tag.hasKey(NBT_CHILD)) { if (tag.hasKey(NBT_CHILD)) {
child = TileController.readCraftingTask(world, tag.getCompoundTag(NBT_CHILD)); child = TileController.readCraftingTask(world, depth + 1, tag.getCompoundTag(NBT_CHILD));
} }
} }

View File

@@ -27,8 +27,8 @@ public final class NetworkUtils {
return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT); return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
} }
public static ICraftingTask createCraftingTask(INetworkMaster network, ICraftingPattern pattern) { public static ICraftingTask createCraftingTask(INetworkMaster network, int depth, ICraftingPattern pattern) {
return RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(pattern.getId()).create(network.getNetworkWorld(), null, pattern); return RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(pattern.getId()).create(network.getNetworkWorld(), depth, null, pattern);
} }
public static boolean hasPattern(INetworkMaster network, ItemStack stack) { public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
@@ -62,7 +62,7 @@ public final class NetworkUtils {
ICraftingPattern pattern = network.getPattern(stack, compare); ICraftingPattern pattern = network.getPattern(stack, compare);
if (pattern != null) { if (pattern != null) {
network.addCraftingTask(createCraftingTask(network, pattern)); network.addCraftingTask(createCraftingTask(network, 0, pattern));
} }
} }
} }

View File

@@ -23,6 +23,7 @@ public class CraftingPreviewData {
private void calculate(ItemStack stack, int quantity, boolean baseStack) { private void calculate(ItemStack stack, int quantity, boolean baseStack) {
quantity = -add(stack, quantity, baseStack); quantity = -add(stack, quantity, baseStack);
if (quantity > 0) { if (quantity > 0) {
ICraftingPattern pattern = NetworkUtils.getPattern(network, stack); ICraftingPattern pattern = NetworkUtils.getPattern(network, stack);

View File

@@ -21,8 +21,8 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
@Override @Override
@Nonnull @Nonnull
public ICraftingTask create(World world, @Nullable NBTTagCompound tag, ICraftingPattern pattern) { public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern) {
CraftingTaskNormal task = new CraftingTaskNormal(pattern); CraftingTaskNormal task = new CraftingTaskNormal(pattern, depth);
if (tag != null) { if (tag != null) {
task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED)); task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED));

View File

@@ -22,8 +22,8 @@ public class CraftingTaskFactoryProcessing implements ICraftingTaskFactory {
@Override @Override
@Nonnull @Nonnull
public ICraftingTask create(World world, @Nullable NBTTagCompound tag, ICraftingPattern pattern) { public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern) {
CraftingTaskProcessing task = new CraftingTaskProcessing(pattern); CraftingTaskProcessing task = new CraftingTaskProcessing(pattern, depth);
if (tag != null) { if (tag != null) {
task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED)); task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED));

View File

@@ -8,8 +8,8 @@ import refinedstorage.api.network.INetworkMaster;
import refinedstorage.apiimpl.storage.fluid.FluidUtils; import refinedstorage.apiimpl.storage.fluid.FluidUtils;
public class CraftingTaskNormal extends CraftingTask { public class CraftingTaskNormal extends CraftingTask {
public CraftingTaskNormal(ICraftingPattern pattern) { public CraftingTaskNormal(ICraftingPattern pattern, int depth) {
super(pattern); super(pattern, depth);
} }
@Override @Override

View File

@@ -22,8 +22,8 @@ public class CraftingTaskProcessing extends CraftingTask {
private boolean waitingOnTileInUse; private boolean waitingOnTileInUse;
public CraftingTaskProcessing(ICraftingPattern pattern) { public CraftingTaskProcessing(ICraftingPattern pattern, int depth) {
super(pattern); super(pattern, depth);
this.satisfiedInsertion = new boolean[pattern.getOutputs().size()]; this.satisfiedInsertion = new boolean[pattern.getOutputs().size()];
} }

View File

@@ -136,7 +136,7 @@ public class ItemGridHandler implements IItemGridHandler {
int quantityPerRequest = pattern.getQuantityPerRequest(stack); int quantityPerRequest = pattern.getQuantityPerRequest(stack);
while (quantity > 0) { while (quantity > 0) {
network.addCraftingTask(NetworkUtils.createCraftingTask(network, pattern)); network.addCraftingTask(NetworkUtils.createCraftingTask(network, 0, pattern));
quantity -= quantityPerRequest; quantity -= quantityPerRequest;
} }

View File

@@ -123,7 +123,7 @@ public class GuiCraftingPreview extends GuiBase {
String format = stack.cantCraft() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft"; String format = stack.cantCraft() ? "gui.refinedstorage:crafting_preview.missing" : "gui.refinedstorage:crafting_preview.to_craft";
drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t(format, stack.getToCraft())); drawString(calculateOffsetOnScale(x + 23, scale), calculateOffsetOnScale(yy, scale), t(format, stack.getToCraft()));
yy += 15; yy += 7;
} }
if (stack.getStock() > 0) { if (stack.getStock() > 0) {

View File

@@ -243,7 +243,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
if (!craftingTasksToRead.isEmpty()) { if (!craftingTasksToRead.isEmpty()) {
for (NBTTagCompound tag : craftingTasksToRead) { for (NBTTagCompound tag : craftingTasksToRead) {
ICraftingTask task = readCraftingTask(worldObj, tag); ICraftingTask task = readCraftingTask(worldObj, 0, tag);
if (task != null) { if (task != null) {
addCraftingTask(task); addCraftingTask(task);
@@ -703,7 +703,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
} }
} }
public static ICraftingTask readCraftingTask(World world, NBTTagCompound tag) { public static ICraftingTask readCraftingTask(World world, int depth, NBTTagCompound tag) {
ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag(CraftingTask.NBT_PATTERN_STACK)); ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag(CraftingTask.NBT_PATTERN_STACK));
if (stack != null && stack.getItem() instanceof ICraftingPatternProvider) { if (stack != null && stack.getItem() instanceof ICraftingPatternProvider) {
@@ -715,7 +715,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
ICraftingTaskFactory factory = RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(tag.getString(CraftingTask.NBT_PATTERN_TYPE)); ICraftingTaskFactory factory = RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(tag.getString(CraftingTask.NBT_PATTERN_TYPE));
if (factory != null) { if (factory != null) {
return factory.create(world, tag, pattern); return factory.create(world, depth, tag, pattern);
} }
} }
} }