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 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 parent the parent task
* @param pattern the pattern
* @return the crafting task
*/
@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 ICraftingPattern pattern;
protected ICraftingTask parent;
protected ICraftingTask child;
protected List<ItemStack> took = new ArrayList<>();
@@ -42,8 +41,7 @@ public abstract class CraftingTask implements ICraftingTask {
protected boolean satisfied[];
protected boolean checked[];
public CraftingTask(@Nullable ICraftingTask parent, ICraftingPattern pattern, int depth) {
this.parent = parent;
public CraftingTask(ICraftingPattern pattern, int depth) {
this.pattern = pattern;
this.childrenCreated = 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));
if (pattern != null) {
child = NetworkUtils.createCraftingTask(network, depth + 1, this, pattern);
child = NetworkUtils.createCraftingTask(network, depth + 1, pattern);
childrenCreated[i] = true;
}
@@ -150,7 +148,7 @@ public abstract class CraftingTask implements ICraftingTask {
public void readChildNBT(World world, NBTTagCompound tag) {
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.storage.CompareUtils;
import javax.annotation.Nullable;
/**
* Utilities for network manipulation.
*/
@@ -29,8 +27,8 @@ public final class NetworkUtils {
return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
}
public static ICraftingTask createCraftingTask(INetworkMaster network, int depth, @Nullable ICraftingTask parent, ICraftingPattern pattern) {
return RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(pattern.getId()).create(network.getNetworkWorld(), depth, null, parent, pattern);
public static ICraftingTask createCraftingTask(INetworkMaster network, int depth, ICraftingPattern pattern) {
return RefinedStorageAPI.instance().getCraftingTaskRegistry().getFactory(pattern.getId()).create(network.getNetworkWorld(), depth, null, pattern);
}
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
@@ -64,7 +62,7 @@ public final class NetworkUtils {
ICraftingPattern pattern = network.getPattern(stack, compare);
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
@Nonnull
public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, @Nullable ICraftingTask parent, ICraftingPattern pattern) {
CraftingTaskNormal task = new CraftingTaskNormal(parent, pattern, depth);
public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern) {
CraftingTaskNormal task = new CraftingTaskNormal(pattern, depth);
if (tag != null) {
task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED));

View File

@@ -22,8 +22,8 @@ public class CraftingTaskFactoryProcessing implements ICraftingTaskFactory {
@Override
@Nonnull
public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, @Nullable ICraftingTask parent, ICraftingPattern pattern) {
CraftingTaskProcessing task = new CraftingTaskProcessing(parent, pattern, depth);
public ICraftingTask create(World world, int depth, @Nullable NBTTagCompound tag, ICraftingPattern pattern) {
CraftingTaskProcessing task = new CraftingTaskProcessing(pattern, depth);
if (tag != null) {
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 refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.task.CraftingTask;
import refinedstorage.api.autocrafting.task.ICraftingTask;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
import javax.annotation.Nullable;
public class CraftingTaskNormal extends CraftingTask {
public CraftingTaskNormal(@Nullable ICraftingTask parent, ICraftingPattern pattern, int depth) {
super(parent, pattern, depth);
public CraftingTaskNormal(ICraftingPattern pattern, int depth) {
super(pattern, depth);
}
@Override

View File

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

View File

@@ -243,7 +243,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
if (!craftingTasksToRead.isEmpty()) {
for (NBTTagCompound tag : craftingTasksToRead) {
ICraftingTask task = readCraftingTask(worldObj, null, 0, tag);
ICraftingTask task = readCraftingTask(worldObj, 0, tag);
if (task != null) {
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));
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));
if (factory != null) {
return factory.create(world, depth, tag, parent, pattern);
return factory.create(world, depth, tag, pattern);
}
}
}