Various improvements

This commit is contained in:
Raoul Van den Berge
2016-08-29 03:03:51 +02:00
parent 71f7338393
commit 3c0aabfc52
8 changed files with 55 additions and 23 deletions

View File

@@ -7,7 +7,17 @@ import refinedstorage.api.autocrafting.task.ICraftingTask;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/**
* A factory that creates a crafting task from a NBT tag and crafting pattern.
*/
public interface ICraftingTaskFactory { 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 @Nonnull
ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern); ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern);
} }

View File

@@ -1,7 +1,24 @@
package refinedstorage.api.autocrafting.registry; package refinedstorage.api.autocrafting.registry;
/**
* A registry that stores the various crafting task types.
*/
public interface ICraftingTaskRegistry { 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); 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); ICraftingTaskFactory getFactory(String id);
} }

View File

@@ -9,6 +9,7 @@ import net.minecraftforge.common.util.Constants;
import refinedstorage.api.autocrafting.ICraftingPattern; import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingPatternContainer; import refinedstorage.api.autocrafting.ICraftingPatternContainer;
import refinedstorage.api.storage.CompareUtils; import refinedstorage.api.storage.CompareUtils;
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal;
import refinedstorage.item.ItemPattern; import refinedstorage.item.ItemPattern;
import refinedstorage.tile.TileCrafter; import refinedstorage.tile.TileCrafter;
@@ -64,7 +65,7 @@ public class CraftingPattern implements ICraftingPattern {
@Override @Override
public String getId() { public String getId() {
return processing ? "processing" : "normal"; return processing ? "processing" : CraftingTaskFactoryNormal.ID;
} }
@Override @Override

View File

@@ -15,11 +15,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CraftingTaskFactoryNormal implements ICraftingTaskFactory { public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
public static final String ID = "normal";
@Override @Override
@Nonnull @Nonnull
public ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern) { public ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern) {
CraftingTaskNormal task = new CraftingTaskNormal(pattern); CraftingTaskNormal task = new CraftingTaskNormal(pattern);
if (tag != null) {
task.setChildrenCreated(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_CHILDREN)); task.setChildrenCreated(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_CHILDREN));
task.setSatisfied(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_SATISFIED)); task.setSatisfied(CraftingTaskNormal.readBooleanArray(tag, CraftingTaskNormal.NBT_SATISFIED));
@@ -36,6 +39,7 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
} }
task.setTook(took); task.setTook(took);
}
return task; return task;
} }

View File

@@ -115,8 +115,8 @@ public class GuiCraftingMonitor extends GuiBase {
GlStateManager.popMatrix(); GlStateManager.popMatrix();
if (inBounds(x + 5, y + 10, 16, 16, mouseX, mouseY) && !task.getInfo().trim().equals("")) { if (inBounds(x + 5, y + 10, 16, 16, mouseX, mouseY) && !task.getStatus().trim().equals("")) {
lines = task.getInfo().split("\n"); lines = task.getStatus().split("\n");
for (int j = 0; j < lines.length; ++j) { for (int j = 0; j < lines.length; ++j) {
String line = lines[j]; String line = lines[j];

View File

@@ -48,7 +48,7 @@ public class CommonProxy {
RefinedStorageAPI.SOLDERER_REGISTRY = new SoldererRegistry(); RefinedStorageAPI.SOLDERER_REGISTRY = new SoldererRegistry();
RefinedStorageAPI.CRAFTING_TASK_REGISTRY = new CraftingTaskRegistry(); 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; int id = 0;

View File

@@ -5,19 +5,19 @@ import net.minecraft.item.ItemStack;
public class ClientCraftingTask { public class ClientCraftingTask {
private ItemStack output; private ItemStack output;
private int id; private int id;
private String info; private String status;
// Used server-side while sending // Used server-side while sending
private ItemStack[] outputs; private ItemStack[] outputs;
public ClientCraftingTask(ItemStack output, int id, String info) { public ClientCraftingTask(ItemStack output, int id, String status) {
this.output = output; this.output = output;
this.id = id; this.id = id;
this.info = info; this.status = status;
} }
public ClientCraftingTask(String info, ItemStack[] outputs) { public ClientCraftingTask(String status, ItemStack[] outputs) {
this.info = info; this.status = status;
this.outputs = outputs; this.outputs = outputs;
} }
@@ -33,7 +33,7 @@ public class ClientCraftingTask {
return id; return id;
} }
public String getInfo() { public String getStatus() {
return info; return status;
} }
} }

View File

@@ -53,7 +53,7 @@ public final class RefinedStorageSerializers {
buf.writeInt(tasks.size()); buf.writeInt(tasks.size());
for (ClientCraftingTask task : tasks) { for (ClientCraftingTask task : tasks) {
ByteBufUtils.writeUTF8String(buf, task.getInfo()); ByteBufUtils.writeUTF8String(buf, task.getStatus());
buf.writeInt(task.getOutputs().length); buf.writeInt(task.getOutputs().length);