@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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,9 +102,11 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTileInUse(INetworkMaster network) {
|
private boolean isTileInUse(INetworkMaster network) {
|
||||||
for (ICraftingTask task : network.getCraftingTasks()) {
|
if (tileInUse == null) {
|
||||||
if (isTileInUse(task)) {
|
for (ICraftingTask task : network.getCraftingTasks()) {
|
||||||
return true;
|
if (isTileInUse(task)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,20 +134,22 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean onInserted(ItemStack stack) {
|
public boolean onInserted(ItemStack stack) {
|
||||||
if (!hasReceivedOutputs() && hasTakenInputs()) {
|
if (isReady()) {
|
||||||
for (int i = 0; i < pattern.getOutputs().size(); ++i) {
|
return false;
|
||||||
ItemStack output = pattern.getOutputs().get(i);
|
}
|
||||||
|
|
||||||
if (!satisfiedInsertion[i]) {
|
for (int i = 0; i < pattern.getOutputs().size(); ++i) {
|
||||||
if (CompareUtils.compareStackNoQuantity(output, stack)) {
|
ItemStack output = pattern.getOutputs().get(i);
|
||||||
satisfiedInsertion[i] = true;
|
|
||||||
|
|
||||||
if (hasReceivedOutputs() && parent != null) {
|
if (!satisfiedInsertion[i]) {
|
||||||
parent.setChild(null);
|
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");
|
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) {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user