Revert "Another go at fixing #389"

This reverts commit 04aafa90ae.
This commit is contained in:
Raoul Van den Berge
2016-10-01 12:59:45 +02:00
parent 04aafa90ae
commit 0d99774db5
9 changed files with 41 additions and 47 deletions

View File

@@ -19,10 +19,9 @@ public interface ICraftingTaskFactory {
* @param world the world * @param world the world
* @param depth the depth of the crafting task to create * @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 parent the parent task
* @param pattern the pattern * @param pattern the pattern
* @return the crafting task * @return the crafting task
*/ */
@Nonnull @Nonnull
ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, @Nullable ICraftingTask parent, ICraftingPattern pattern); ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern);
} }

View File

@@ -33,7 +33,6 @@ public abstract class CraftingTask implements ICraftingTask {
protected int depth; protected int depth;
protected ICraftingPattern pattern; protected ICraftingPattern pattern;
protected ICraftingTask parent;
protected ICraftingTask child; protected ICraftingTask child;
protected List<ItemStack> took = new ArrayList<>(); protected List<ItemStack> took = new ArrayList<>();
@@ -42,8 +41,7 @@ public abstract class CraftingTask implements ICraftingTask {
protected boolean satisfied[]; protected boolean satisfied[];
protected boolean checked[]; protected boolean checked[];
public CraftingTask(@Nullable ICraftingTask parent, ICraftingPattern pattern, int depth) { public CraftingTask(ICraftingPattern pattern, int depth) {
this.parent = parent;
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()];
@@ -93,7 +91,7 @@ public abstract class CraftingTask implements ICraftingTask {
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, depth + 1, this, pattern); child = NetworkUtils.createCraftingTask(network, depth + 1, pattern);
childrenCreated[i] = true; childrenCreated[i] = true;
} }
@@ -150,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, this, depth + 1, tag.getCompoundTag(NBT_CHILD)); child = TileController.readCraftingTask(world, depth + 1, tag.getCompoundTag(NBT_CHILD));
} }
} }

View File

@@ -11,8 +11,6 @@ import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.task.ICraftingTask; import refinedstorage.api.autocrafting.task.ICraftingTask;
import refinedstorage.api.storage.CompareUtils; import refinedstorage.api.storage.CompareUtils;
import javax.annotation.Nullable;
/** /**
* Utilities for network manipulation. * Utilities for network manipulation.
*/ */
@@ -29,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, int depth, @Nullable ICraftingTask parent, ICraftingPattern pattern) { public static ICraftingTask createCraftingTask(INetworkMaster network, int depth, ICraftingPattern pattern) {
return RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(pattern.getId()).create(network.getNetworkWorld(), depth, null, parent, 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) {
@@ -64,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, 0, null, pattern)); network.addCraftingTask(createCraftingTask(network, 0, pattern));
} }
} }
} }

View File

@@ -21,8 +21,8 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
@Override @Override
@Nonnull @Nonnull
public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, @Nullable ICraftingTask parent, ICraftingPattern pattern) { public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern) {
CraftingTaskNormal task = new CraftingTaskNormal(parent, pattern, depth); 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, int depth, @Nullable NBTTagCompound tag, @Nullable ICraftingTask parent, ICraftingPattern pattern) { public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern) {
CraftingTaskProcessing task = new CraftingTaskProcessing(parent, pattern, depth); 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

@@ -4,15 +4,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import refinedstorage.api.autocrafting.ICraftingPattern; import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.task.CraftingTask; import refinedstorage.api.autocrafting.task.CraftingTask;
import refinedstorage.api.autocrafting.task.ICraftingTask;
import refinedstorage.api.network.INetworkMaster; import refinedstorage.api.network.INetworkMaster;
import refinedstorage.apiimpl.storage.fluid.FluidUtils; import refinedstorage.apiimpl.storage.fluid.FluidUtils;
import javax.annotation.Nullable;
public class CraftingTaskNormal extends CraftingTask { public class CraftingTaskNormal extends CraftingTask {
public CraftingTaskNormal(@Nullable ICraftingTask parent, ICraftingPattern pattern, int depth) { public CraftingTaskNormal(ICraftingPattern pattern, int depth) {
super(parent, pattern, depth); super(pattern, depth);
} }
@Override @Override

View File

@@ -13,8 +13,6 @@ import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.storage.CompareUtils; import refinedstorage.api.storage.CompareUtils;
import refinedstorage.apiimpl.storage.fluid.FluidUtils; import refinedstorage.apiimpl.storage.fluid.FluidUtils;
import javax.annotation.Nullable;
public class CraftingTaskProcessing extends CraftingTask { public class CraftingTaskProcessing extends CraftingTask {
public static final String NBT_SATISFIED_INSERTION = "SatisfiedInsertion"; public static final String NBT_SATISFIED_INSERTION = "SatisfiedInsertion";
public static final String NBT_TILE_IN_USE = "TileInUse"; public static final String NBT_TILE_IN_USE = "TileInUse";
@@ -22,8 +20,8 @@ public class CraftingTaskProcessing extends CraftingTask {
private boolean satisfiedInsertion[]; private boolean satisfiedInsertion[];
private BlockPos tileInUse; private BlockPos tileInUse;
public CraftingTaskProcessing(@Nullable ICraftingTask parent, ICraftingPattern pattern, int depth) { public CraftingTaskProcessing(ICraftingPattern pattern, int depth) {
super(parent, pattern, depth); super(pattern, depth);
this.satisfiedInsertion = new boolean[pattern.getOutputs().size()]; this.satisfiedInsertion = new boolean[pattern.getOutputs().size()];
} }
@@ -58,7 +56,7 @@ public class CraftingTaskProcessing extends CraftingTask {
} }
} }
if (!hasTakenInputs()) { if (!isReadyToInsert()) {
return false; return false;
} }
@@ -80,10 +78,10 @@ public class CraftingTaskProcessing extends CraftingTask {
tileInUse = null; tileInUse = null;
} }
return hasReceivedOutputs(); return isReady();
} }
public boolean hasReceivedOutputs() { private boolean isReady() {
for (boolean item : satisfiedInsertion) { for (boolean item : satisfiedInsertion) {
if (!item) { if (!item) {
return false; return false;
@@ -93,7 +91,7 @@ public class CraftingTaskProcessing extends CraftingTask {
return true; return true;
} }
private boolean hasTakenInputs() { private boolean isReadyToInsert() {
for (boolean item : satisfied) { for (boolean item : satisfied) {
if (!item) { if (!item) {
return false; return false;
@@ -104,11 +102,13 @@ public class CraftingTaskProcessing extends CraftingTask {
} }
private boolean isTileInUse(INetworkMaster network) { private boolean isTileInUse(INetworkMaster network) {
if (tileInUse == null) {
for (ICraftingTask task : network.getCraftingTasks()) { for (ICraftingTask task : network.getCraftingTasks()) {
if (isTileInUse(task)) { if (isTileInUse(task)) {
return true; return true;
} }
} }
}
return false; return false;
} }
@@ -134,7 +134,10 @@ public class CraftingTaskProcessing extends CraftingTask {
} }
public boolean onInserted(ItemStack stack) { public boolean onInserted(ItemStack stack) {
if (!hasReceivedOutputs() && hasTakenInputs()) { if (isReady()) {
return false;
}
for (int i = 0; i < pattern.getOutputs().size(); ++i) { for (int i = 0; i < pattern.getOutputs().size(); ++i) {
ItemStack output = pattern.getOutputs().get(i); ItemStack output = pattern.getOutputs().get(i);
@@ -142,15 +145,14 @@ public class CraftingTaskProcessing extends CraftingTask {
if (CompareUtils.compareStackNoQuantity(output, stack)) { if (CompareUtils.compareStackNoQuantity(output, stack)) {
satisfiedInsertion[i] = true; satisfiedInsertion[i] = true;
if (hasReceivedOutputs() && parent != null) { if (isReady()) {
parent.setChild(null); tileInUse = null;
} }
return true; return true;
} }
} }
} }
}
return false; return false;
} }
@@ -204,7 +206,7 @@ public class CraftingTaskProcessing extends CraftingTask {
} }
} }
if (hasTakenInputs()) { if (isReadyToInsert()) {
builder.append("I=gui.refinedstorage:crafting_monitor.items_processing\n"); builder.append("I=gui.refinedstorage:crafting_monitor.items_processing\n");
for (int i = 0; i < pattern.getInputs().size(); ++i) { for (int i = 0; i < pattern.getInputs().size(); ++i) {

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, 0, null, pattern)); network.addCraftingTask(NetworkUtils.createCraftingTask(network, 0, pattern));
quantity -= quantityPerRequest; quantity -= quantityPerRequest;
} }

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, null, 0, 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, ICraftingTask parent, int depth, 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, depth, tag, parent, pattern); return factory.create(world, depth, tag, pattern);
} }
} }
} }