Move CraftingTask with some getters to the API package
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package refinedstorage.apiimpl.autocrafting.task;
|
||||
package refinedstorage.api.autocrafting.task;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -6,7 +6,6 @@ import net.minecraft.nbt.NBTTagIntArray;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.network.NetworkUtils;
|
||||
import refinedstorage.tile.TileController;
|
||||
@@ -15,8 +14,13 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A default implementation for crafting tasks.
|
||||
*/
|
||||
public abstract class CraftingTask implements ICraftingTask {
|
||||
public static final String NBT_CHILDREN_CREATED = "ChildrenCreated";
|
||||
public static final String NBT_SATISFIED = "Satisfied";
|
||||
public static final String NBT_CHECKED = "Checked";
|
||||
public static final String NBT_TOOK = "Took";
|
||||
private static final String NBT_CHILD = "Child";
|
||||
|
||||
@@ -24,11 +28,16 @@ public abstract class CraftingTask implements ICraftingTask {
|
||||
protected ICraftingTask child;
|
||||
|
||||
protected List<ItemStack> took = new ArrayList<>();
|
||||
|
||||
protected boolean childrenCreated[];
|
||||
protected boolean satisfied[];
|
||||
protected boolean checked[];
|
||||
|
||||
public CraftingTask(ICraftingPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
this.childrenCreated = new boolean[pattern.getInputs().size()];
|
||||
this.satisfied = new boolean[pattern.getInputs().size()];
|
||||
this.checked = new boolean[pattern.getInputs().size()];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,10 +49,34 @@ public abstract class CraftingTask implements ICraftingTask {
|
||||
this.took = took;
|
||||
}
|
||||
|
||||
public List<ItemStack> getTook() {
|
||||
return took;
|
||||
}
|
||||
|
||||
public boolean[] getChildrenCreated() {
|
||||
return childrenCreated;
|
||||
}
|
||||
|
||||
public void setChildrenCreated(boolean[] childrenCreated) {
|
||||
this.childrenCreated = childrenCreated;
|
||||
}
|
||||
|
||||
public boolean[] getSatisfied() {
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
public void setSatisfied(boolean[] satisfied) {
|
||||
this.satisfied = satisfied;
|
||||
}
|
||||
|
||||
public boolean[] getChecked() {
|
||||
return checked;
|
||||
}
|
||||
|
||||
public void setChecked(boolean[] checked) {
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
protected void tryCreateChild(INetworkMaster network, int i) {
|
||||
if (!childrenCreated[i]) {
|
||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, this.pattern.getInputs().get(i));
|
||||
@@ -88,6 +121,8 @@ public abstract class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
|
||||
writeBooleanArray(tag, NBT_CHILDREN_CREATED, childrenCreated);
|
||||
writeBooleanArray(tag, NBT_SATISFIED, satisfied);
|
||||
writeBooleanArray(tag, NBT_CHECKED, checked);
|
||||
|
||||
NBTTagList took = new NBTTagList();
|
||||
|
||||
@@ -7,8 +7,8 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
||||
import refinedstorage.api.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTaskNormal;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -26,8 +26,8 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
|
||||
|
||||
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));
|
||||
task.setSatisfied(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_SATISFIED));
|
||||
task.setChecked(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHECKED));
|
||||
|
||||
List<ItemStack> took = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
||||
import refinedstorage.api.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.apiimpl.autocrafting.task.CraftingTaskProcessing;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -26,9 +26,9 @@ public class CraftingTaskFactoryProcessing implements ICraftingTaskFactory {
|
||||
|
||||
if (tag != null) {
|
||||
task.setChildrenCreated(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHILDREN_CREATED));
|
||||
task.setSatisfied(CraftingTask.readBooleanArray(tag, CraftingTaskProcessing.NBT_SATISFIED));
|
||||
task.setSatisfied(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_SATISFIED));
|
||||
task.setSatisfiedInsertion(CraftingTask.readBooleanArray(tag, CraftingTaskProcessing.NBT_SATISFIED_INSERTION));
|
||||
task.setChecked(CraftingTask.readBooleanArray(tag, CraftingTaskProcessing.NBT_CHECKED));
|
||||
task.setChecked(CraftingTask.readBooleanArray(tag, CraftingTask.NBT_CHECKED));
|
||||
|
||||
List<ItemStack> took = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -1,32 +1,15 @@
|
||||
package refinedstorage.apiimpl.autocrafting.task;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
|
||||
|
||||
public class CraftingTaskNormal extends CraftingTask {
|
||||
public static final String NBT_SATISFIED = "Satisfied";
|
||||
public static final String NBT_CHECKED = "Checked";
|
||||
|
||||
private boolean satisfied[];
|
||||
private boolean checked[];
|
||||
|
||||
public CraftingTaskNormal(ICraftingPattern pattern) {
|
||||
super(pattern);
|
||||
|
||||
this.satisfied = new boolean[pattern.getInputs().size()];
|
||||
this.checked = new boolean[pattern.getInputs().size()];
|
||||
}
|
||||
|
||||
public void setSatisfied(boolean[] satisfied) {
|
||||
this.satisfied = satisfied;
|
||||
}
|
||||
|
||||
public void setChecked(boolean[] checked) {
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,16 +50,6 @@ public class CraftingTaskNormal extends CraftingTask {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
writeBooleanArray(tag, NBT_SATISFIED, satisfied);
|
||||
writeBooleanArray(tag, NBT_CHECKED, checked);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
@@ -6,39 +6,26 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||
import refinedstorage.api.autocrafting.task.CraftingTask;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.apiimpl.storage.fluid.FluidUtils;
|
||||
|
||||
public class CraftingTaskProcessing extends CraftingTask {
|
||||
public static final String NBT_SATISFIED = "Satisfied";
|
||||
public static final String NBT_SATISFIED_INSERTION = "SatisfiedInsertion";
|
||||
public static final String NBT_CHECKED = "Checked";
|
||||
|
||||
private boolean satisfied[];
|
||||
private boolean satisfiedInsertion[];
|
||||
private boolean checked[];
|
||||
|
||||
public CraftingTaskProcessing(ICraftingPattern pattern) {
|
||||
super(pattern);
|
||||
|
||||
this.satisfied = new boolean[pattern.getInputs().size()];
|
||||
this.satisfiedInsertion = new boolean[pattern.getOutputs().size()];
|
||||
this.checked = new boolean[pattern.getInputs().size()];
|
||||
}
|
||||
|
||||
public void setSatisfied(boolean[] satisfied) {
|
||||
this.satisfied = satisfied;
|
||||
}
|
||||
|
||||
public void setSatisfiedInsertion(boolean[] satisfiedInsertion) {
|
||||
this.satisfiedInsertion = satisfiedInsertion;
|
||||
}
|
||||
|
||||
public void setChecked(boolean[] checked) {
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(World world, INetworkMaster network) {
|
||||
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||
@@ -79,10 +66,10 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
}
|
||||
}
|
||||
|
||||
return isDone();
|
||||
return isReady();
|
||||
}
|
||||
|
||||
private boolean isDone() {
|
||||
private boolean isReady() {
|
||||
for (boolean item : satisfiedInsertion) {
|
||||
if (!item) {
|
||||
return false;
|
||||
@@ -92,8 +79,18 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isReadyToInsert() {
|
||||
for (boolean item : satisfied) {
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onInserted(ItemStack stack) {
|
||||
if (isDone()) {
|
||||
if (isReady()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -116,23 +113,11 @@ public class CraftingTaskProcessing extends CraftingTask {
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
||||
writeBooleanArray(tag, NBT_SATISFIED, satisfied);
|
||||
writeBooleanArray(tag, NBT_SATISFIED_INSERTION, satisfiedInsertion);
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user