Various improvements
This commit is contained in:
@@ -7,7 +7,17 @@ import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A factory that creates a crafting task from a NBT tag and crafting pattern.
|
||||
*/
|
||||
public interface ICraftingTaskFactory {
|
||||
/**
|
||||
* Returns a crafting task for a given NBT tag and pattern.
|
||||
*
|
||||
* @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 pattern The pattern
|
||||
* @return The crafting task
|
||||
*/
|
||||
@Nonnull
|
||||
ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
package refinedstorage.api.autocrafting.registry;
|
||||
|
||||
/**
|
||||
* A registry that stores the various crafting task types.
|
||||
*/
|
||||
public interface ICraftingTaskRegistry {
|
||||
/**
|
||||
* Adds a crafting task factory to the registry.
|
||||
* The id is used for reading and writing the crafting tasks to disk.
|
||||
*
|
||||
* @param id The id of the crafting task type
|
||||
* @param factory The factory
|
||||
*/
|
||||
void addFactory(String id, ICraftingTaskFactory factory);
|
||||
|
||||
/**
|
||||
* Returns the factory of a crafting task type.
|
||||
* This is used when reading the storage network from disk to get a factory in order to create a crafting task.
|
||||
*
|
||||
* @param id The id
|
||||
* @return The factory
|
||||
*/
|
||||
ICraftingTaskFactory getFactory(String id);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraftforge.common.util.Constants;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
import refinedstorage.tile.TileCrafter;
|
||||
|
||||
@@ -64,7 +65,7 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return processing ? "processing" : "normal";
|
||||
return processing ? "processing" : CraftingTaskFactoryNormal.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,27 +15,31 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
|
||||
public static final String ID = "normal";
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern) {
|
||||
CraftingTaskNormal task = new CraftingTaskNormal(pattern);
|
||||
|
||||
task.setChildrenCreated(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_CHILDREN));
|
||||
task.setSatisfied(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_SATISFIED));
|
||||
if (tag != null) {
|
||||
task.setChildrenCreated(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_CHILDREN));
|
||||
task.setSatisfied(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_SATISFIED));
|
||||
|
||||
List<ItemStack> took = new ArrayList<>();
|
||||
List<ItemStack> took = new ArrayList<>();
|
||||
|
||||
NBTTagList tookTag = tag.getTagList(CraftingTaskNormal.NBT_TOOK, Constants.NBT.TAG_COMPOUND);
|
||||
NBTTagList tookTag = tag.getTagList(CraftingTaskNormal.NBT_TOOK, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < tookTag.tagCount(); ++i) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tookTag.getCompoundTagAt(i));
|
||||
for (int i = 0; i < tookTag.tagCount(); ++i) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tookTag.getCompoundTagAt(i));
|
||||
|
||||
if (stack != null) {
|
||||
took.add(stack);
|
||||
if (stack != null) {
|
||||
took.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task.setTook(took);
|
||||
task.setTook(took);
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public class GuiCraftingMonitor extends GuiBase {
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
if (inBounds(x + 5, y + 10, 16, 16, mouseX, mouseY) && !task.getInfo().trim().equals("")) {
|
||||
lines = task.getInfo().split("\n");
|
||||
if (inBounds(x + 5, y + 10, 16, 16, mouseX, mouseY) && !task.getStatus().trim().equals("")) {
|
||||
lines = task.getStatus().split("\n");
|
||||
|
||||
for (int j = 0; j < lines.length; ++j) {
|
||||
String line = lines[j];
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CommonProxy {
|
||||
RefinedStorageAPI.SOLDERER_REGISTRY = new SoldererRegistry();
|
||||
|
||||
RefinedStorageAPI.CRAFTING_TASK_REGISTRY = new CraftingTaskRegistry();
|
||||
RefinedStorageAPI.CRAFTING_TASK_REGISTRY.addFactory("normal", new CraftingTaskFactoryNormal());
|
||||
RefinedStorageAPI.CRAFTING_TASK_REGISTRY.addFactory(CraftingTaskFactoryNormal.ID, new CraftingTaskFactoryNormal());
|
||||
|
||||
int id = 0;
|
||||
|
||||
|
||||
@@ -5,19 +5,19 @@ import net.minecraft.item.ItemStack;
|
||||
public class ClientCraftingTask {
|
||||
private ItemStack output;
|
||||
private int id;
|
||||
private String info;
|
||||
private String status;
|
||||
|
||||
// Used server-side while sending
|
||||
private ItemStack[] outputs;
|
||||
|
||||
public ClientCraftingTask(ItemStack output, int id, String info) {
|
||||
public ClientCraftingTask(ItemStack output, int id, String status) {
|
||||
this.output = output;
|
||||
this.id = id;
|
||||
this.info = info;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ClientCraftingTask(String info, ItemStack[] outputs) {
|
||||
this.info = info;
|
||||
public ClientCraftingTask(String status, ItemStack[] outputs) {
|
||||
this.status = status;
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ClientCraftingTask {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
return info;
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class RefinedStorageSerializers {
|
||||
buf.writeInt(tasks.size());
|
||||
|
||||
for (ClientCraftingTask task : tasks) {
|
||||
ByteBufUtils.writeUTF8String(buf, task.getInfo());
|
||||
ByteBufUtils.writeUTF8String(buf, task.getStatus());
|
||||
|
||||
buf.writeInt(task.getOutputs().length);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user