This commit is contained in:
Raoul Van den Berge
2016-10-06 15:25:45 +02:00
parent c3721c2561
commit 61270e0f67
7 changed files with 95 additions and 31 deletions

View File

@@ -1,14 +1,37 @@
package refinedstorage.api.autocrafting.craftingmonitor;
import io.netty.buffer.ByteBuf;
import refinedstorage.gui.GuiBase;
public interface ICraftingMonitorElement {
void draw(GuiBase gui, int x, int y);
/**
* Represents a crafting monitor element.
*/
public interface ICraftingMonitorElement<T> {
/**
* @param gui the gui
* @param x position on the x axis to render
* @param y position on the y axis to render
*/
void draw(T gui, int x, int y);
/**
* Returns the position where the corresponding task is in the crafting task list.
* Used for cancelling tasks.
*
* @return the id, or -1 if no task is associated with this element
*/
int getTaskId();
/**
* Returns the id of this element, used for serialization and deserialization over the network.
*
* @return the id
*/
String getId();
/**
* Writes the data to the network.
*
* @param buf the buffer
*/
void write(ByteBuf buf);
}

View File

@@ -5,9 +5,24 @@ import io.netty.buffer.ByteBuf;
import javax.annotation.Nullable;
import java.util.function.Function;
/**
* This registry holds factories for crafting monitor elements (for deserialization from the network).
*/
public interface ICraftingMonitorElementRegistry {
/**
* Adds a factory to the registry.
*
* @param id the id, as specified in {@link ICraftingMonitorElement#getTaskId()}
* @param factory the factory
*/
void add(String id, Function<ByteBuf, ICraftingMonitorElement> factory);
/**
* Returns a factory from the registry.
*
* @param id the id, as specified in {@link ICraftingMonitorElement#getTaskId()}
* @return the factory, or null if no factory was found
*/
@Nullable
Function<ByteBuf, ICraftingMonitorElement> getFactory(String id);
}

View File

@@ -1,40 +1,62 @@
package refinedstorage.api.autocrafting.task;
import com.google.common.collect.Multimap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import java.util.Deque;
import java.util.List;
/**
* Represents a crafting task.
*/
public interface ICraftingTask {
String NBT_QUANTITY = "Quantity";
String NBT_PATTERN_ID = "PatternID";
String NBT_PATTERN_STACK = "PatternStack";
String NBT_PATTERN_CONTAINER = "PatternContainer";
/**
* Calculates what this task will do, but doesn't run the task just yet.
*/
void calculate();
/**
* Called when this task is cancelled.
*/
void onCancelled();
/**
* Updates this task. Gets called every few ticks, depending on the speed of the pattern container.
*
* @return true if this crafting task is finished and can be deleted from the list, false otherwise
*/
boolean update();
/**
* @return the amount of items that have to be crafted
*/
int getQuantity();
/**
* Writes this task to NBT.
*
* @param tag the tag
* @return the written tag
*/
NBTTagCompound writeToNBT(NBTTagCompound tag);
/**
* @return the elements of this task for display in the crafting monitor
*/
List<ICraftingMonitorElement> getCraftingMonitorElements();
/**
* @return the crafting pattern corresponding to this task
*/
ICraftingPattern getPattern();
Deque<ItemStack> getToTake();
Multimap<Item, ItemStack> getToCraft();
Multimap<Item, ItemStack> getMissing();
/**
* @return the processable items in this task
*/
List<IProcessable> getToProcess();
}

View File

@@ -3,14 +3,33 @@ package refinedstorage.api.autocrafting.task;
import net.minecraft.item.ItemStack;
import refinedstorage.api.autocrafting.ICraftingPattern;
/**
* Represents a item in a crafting task that can be processed.
*/
public interface IProcessable {
/**
* @return the pattern
*/
ICraftingPattern getPattern();
/**
* @return the first stack to attempt inserting
*/
ItemStack getStackToInsert();
/**
* Goes to the next stack to insert.
*/
void nextStack();
/**
* @return whether this processable item has received its items
*/
boolean hasReceivedOutputs();
/**
* @param stack the stack that was inserted in the storage system
* @return whether this item belonged to the processable item
*/
boolean onReceiveOutput(ItemStack stack);
}

View File

@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.gui.GuiBase;
public class CraftingMonitorElementRoot implements ICraftingMonitorElement {
public class CraftingMonitorElementRoot implements ICraftingMonitorElement<GuiBase> {
public static final String ID = "root";
private int id;

View File

@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import refinedstorage.gui.GuiBase;
public class CraftingMonitorElementToTake implements ICraftingMonitorElement {
public class CraftingMonitorElementToTake implements ICraftingMonitorElement<GuiBase> {
public static final String ID = "to_take";
private ItemStack toTake;
@@ -20,7 +20,7 @@ public class CraftingMonitorElementToTake implements ICraftingMonitorElement {
@Override
public void draw(GuiBase gui, int x, int y) {
x += 3;
x += 4;
gui.drawItem(x + 2, y + 1, toTake);

View File

@@ -174,21 +174,6 @@ public class CraftingTaskNormal implements ICraftingTask {
return pattern;
}
@Override
public Deque<ItemStack> getToTake() {
return toTake;
}
@Override
public Multimap<Item, ItemStack> getToCraft() {
return toCraft;
}
@Override
public Multimap<Item, ItemStack> getMissing() {
return missing;
}
@Override
public List<IProcessable> getToProcess() {
return toProcess;