Processing Crafting Tasks, todo add insertion hook
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package refinedstorage.apiimpl.autocrafting.registry;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTaskNormal;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTaskProcessing;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CraftingTaskFactoryProcessing implements ICraftingTaskFactory {
|
||||
public static final String ID = "processing";
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern) {
|
||||
CraftingTaskProcessing task = new CraftingTaskProcessing(pattern);
|
||||
|
||||
if (tag != null) {
|
||||
task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED));
|
||||
task.setSatisfied(CraftingTask.readBooleanArray(tag, CraftingTaskNormal.NBT_SATISFIED));
|
||||
task.setChecked(CraftingTask.readBooleanArray(tag, CraftingTaskNormal.NBT_CHECKED));
|
||||
|
||||
List<ItemStack> took = new ArrayList<>();
|
||||
|
||||
NBTTagList tookTag = tag.getTagList(CraftingTask.NBT_TOOK, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < tookTag.tagCount(); ++i) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tookTag.getCompoundTagAt(i));
|
||||
|
||||
if (stack != null) {
|
||||
took.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
task.setTook(took);
|
||||
|
||||
task.readChildNBT(tag);
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,11 @@ public abstract class CraftingTask implements ICraftingTask {
|
||||
this.childrenCreated = new boolean[pattern.getInputs().length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingPattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public void setTook(List<ItemStack> took) {
|
||||
this.took = took;
|
||||
}
|
||||
|
||||
@@ -29,11 +29,6 @@ public class CraftingTaskNormal extends CraftingTask {
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingPattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(World world, INetworkMaster network) {
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
package refinedstorage.apiimpl.autocrafting.task;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.network.NetworkUtils;
|
||||
|
||||
public class CraftingTaskProcessing extends CraftingTask {
|
||||
public static final String NBT_SATISFIED = "Satisfied";
|
||||
public static final String NBT_CHECKED = "Checked";
|
||||
|
||||
private boolean satisfied[];
|
||||
private boolean checked[];
|
||||
|
||||
public CraftingTaskProcessing(ICraftingPattern pattern) {
|
||||
super(pattern);
|
||||
|
||||
this.satisfied = new boolean[pattern.getInputs().length];
|
||||
this.checked = new boolean[pattern.getInputs().length];
|
||||
}
|
||||
|
||||
public void setSatisfied(boolean[] satisfied) {
|
||||
this.satisfied = satisfied;
|
||||
}
|
||||
|
||||
public void setChecked(boolean[] checked) {
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(World world, INetworkMaster network) {
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
checked[i] = true;
|
||||
|
||||
ItemStack input = pattern.getInputs()[i];
|
||||
|
||||
if (!satisfied[i]) {
|
||||
ItemStack received = NetworkUtils.extractItem(network, input, input.stackSize);
|
||||
|
||||
if (received != null) {
|
||||
satisfied[i] = true;
|
||||
|
||||
took.add(received);
|
||||
|
||||
network.updateCraftingTasks();
|
||||
} else {
|
||||
tryCreateChild(network, i);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isReadyToInsert()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ICraftingPatternContainer container = pattern.getContainer(world);
|
||||
|
||||
if (!took.isEmpty()) {
|
||||
ItemStack toInsert = took.get(0);
|
||||
|
||||
if (ItemHandlerHelper.insertItem(container.getConnectedItems(), toInsert, true) == null) {
|
||||
ItemHandlerHelper.insertItem(container.getConnectedItems(), toInsert, false);
|
||||
|
||||
took.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
writeBooleanArray(tag, NBT_SATISFIED, satisfied);
|
||||
writeBooleanArray(tag, NBT_CHECKED, checked);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
private boolean isReadyToInsert() {
|
||||
for (boolean item : satisfied) {
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
boolean missingItems = false;
|
||||
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
ItemStack input = pattern.getInputs()[i];
|
||||
|
||||
if (!satisfied[i] && !childrenCreated[i]) {
|
||||
if (!missingItems) {
|
||||
builder.append("I=gui.refinedstorage:crafting_monitor.missing_items\n");
|
||||
|
||||
missingItems = true;
|
||||
}
|
||||
|
||||
builder.append("T=").append(input.getUnlocalizedName()).append(".name\n");
|
||||
}
|
||||
}
|
||||
|
||||
boolean itemsCrafting = false;
|
||||
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
ItemStack input = pattern.getInputs()[i];
|
||||
|
||||
if (!satisfied[i] && childrenCreated[i]) {
|
||||
if (!itemsCrafting) {
|
||||
builder.append("I=gui.refinedstorage:crafting_monitor.items_crafting\n");
|
||||
|
||||
itemsCrafting = true;
|
||||
}
|
||||
|
||||
builder.append("T=").append(input.getUnlocalizedName()).append(".name\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (isReadyToInsert()) {
|
||||
builder.append("I=gui.refinedstorage:crafting_monitor.items_processing\n");
|
||||
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
builder.append("T=").append(pattern.getInputs()[i].getUnlocalizedName()).append(".name\n");
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.api.RefinedStorageAPI;
|
||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal;
|
||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryProcessing;
|
||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskRegistry;
|
||||
import refinedstorage.apiimpl.solderer.*;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidStorageNBT;
|
||||
@@ -49,6 +50,7 @@ public class CommonProxy {
|
||||
|
||||
RefinedStorageAPI.CRAFTING_TASK_REGISTRY = new CraftingTaskRegistry();
|
||||
RefinedStorageAPI.CRAFTING_TASK_REGISTRY.addFactory(CraftingTaskFactoryNormal.ID, new CraftingTaskFactoryNormal());
|
||||
RefinedStorageAPI.CRAFTING_TASK_REGISTRY.addFactory(CraftingTaskFactoryProcessing.ID, new CraftingTaskFactoryProcessing());
|
||||
|
||||
int id = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user