Add docs
This commit is contained in:
@@ -1,14 +1,37 @@
|
|||||||
package refinedstorage.api.autocrafting.craftingmonitor;
|
package refinedstorage.api.autocrafting.craftingmonitor;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
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();
|
int getTaskId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the id of this element, used for serialization and deserialization over the network.
|
||||||
|
*
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the data to the network.
|
||||||
|
*
|
||||||
|
* @param buf the buffer
|
||||||
|
*/
|
||||||
void write(ByteBuf buf);
|
void write(ByteBuf buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,24 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This registry holds factories for crafting monitor elements (for deserialization from the network).
|
||||||
|
*/
|
||||||
public interface ICraftingMonitorElementRegistry {
|
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);
|
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
|
@Nullable
|
||||||
Function<ByteBuf, ICraftingMonitorElement> getFactory(String id);
|
Function<ByteBuf, ICraftingMonitorElement> getFactory(String id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,62 @@
|
|||||||
package refinedstorage.api.autocrafting.task;
|
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 net.minecraft.nbt.NBTTagCompound;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||||
|
|
||||||
import java.util.Deque;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a crafting task.
|
||||||
|
*/
|
||||||
public interface ICraftingTask {
|
public interface ICraftingTask {
|
||||||
String NBT_QUANTITY = "Quantity";
|
String NBT_QUANTITY = "Quantity";
|
||||||
String NBT_PATTERN_ID = "PatternID";
|
String NBT_PATTERN_ID = "PatternID";
|
||||||
String NBT_PATTERN_STACK = "PatternStack";
|
String NBT_PATTERN_STACK = "PatternStack";
|
||||||
String NBT_PATTERN_CONTAINER = "PatternContainer";
|
String NBT_PATTERN_CONTAINER = "PatternContainer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates what this task will do, but doesn't run the task just yet.
|
||||||
|
*/
|
||||||
void calculate();
|
void calculate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when this task is cancelled.
|
||||||
|
*/
|
||||||
void onCancelled();
|
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();
|
boolean update();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the amount of items that have to be crafted
|
||||||
|
*/
|
||||||
int getQuantity();
|
int getQuantity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes this task to NBT.
|
||||||
|
*
|
||||||
|
* @param tag the tag
|
||||||
|
* @return the written tag
|
||||||
|
*/
|
||||||
NBTTagCompound writeToNBT(NBTTagCompound tag);
|
NBTTagCompound writeToNBT(NBTTagCompound tag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the elements of this task for display in the crafting monitor
|
||||||
|
*/
|
||||||
List<ICraftingMonitorElement> getCraftingMonitorElements();
|
List<ICraftingMonitorElement> getCraftingMonitorElements();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the crafting pattern corresponding to this task
|
||||||
|
*/
|
||||||
ICraftingPattern getPattern();
|
ICraftingPattern getPattern();
|
||||||
|
|
||||||
Deque<ItemStack> getToTake();
|
/**
|
||||||
|
* @return the processable items in this task
|
||||||
Multimap<Item, ItemStack> getToCraft();
|
*/
|
||||||
|
|
||||||
Multimap<Item, ItemStack> getMissing();
|
|
||||||
|
|
||||||
List<IProcessable> getToProcess();
|
List<IProcessable> getToProcess();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,33 @@ package refinedstorage.api.autocrafting.task;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a item in a crafting task that can be processed.
|
||||||
|
*/
|
||||||
public interface IProcessable {
|
public interface IProcessable {
|
||||||
|
/**
|
||||||
|
* @return the pattern
|
||||||
|
*/
|
||||||
ICraftingPattern getPattern();
|
ICraftingPattern getPattern();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the first stack to attempt inserting
|
||||||
|
*/
|
||||||
ItemStack getStackToInsert();
|
ItemStack getStackToInsert();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Goes to the next stack to insert.
|
||||||
|
*/
|
||||||
void nextStack();
|
void nextStack();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether this processable item has received its items
|
||||||
|
*/
|
||||||
boolean hasReceivedOutputs();
|
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);
|
boolean onReceiveOutput(ItemStack stack);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
|
|||||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||||
import refinedstorage.gui.GuiBase;
|
import refinedstorage.gui.GuiBase;
|
||||||
|
|
||||||
public class CraftingMonitorElementRoot implements ICraftingMonitorElement {
|
public class CraftingMonitorElementRoot implements ICraftingMonitorElement<GuiBase> {
|
||||||
public static final String ID = "root";
|
public static final String ID = "root";
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.ByteBufUtils;
|
|||||||
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
import refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
|
||||||
import refinedstorage.gui.GuiBase;
|
import refinedstorage.gui.GuiBase;
|
||||||
|
|
||||||
public class CraftingMonitorElementToTake implements ICraftingMonitorElement {
|
public class CraftingMonitorElementToTake implements ICraftingMonitorElement<GuiBase> {
|
||||||
public static final String ID = "to_take";
|
public static final String ID = "to_take";
|
||||||
|
|
||||||
private ItemStack toTake;
|
private ItemStack toTake;
|
||||||
@@ -20,7 +20,7 @@ public class CraftingMonitorElementToTake implements ICraftingMonitorElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiBase gui, int x, int y) {
|
public void draw(GuiBase gui, int x, int y) {
|
||||||
x += 3;
|
x += 4;
|
||||||
|
|
||||||
gui.drawItem(x + 2, y + 1, toTake);
|
gui.drawItem(x + 2, y + 1, toTake);
|
||||||
|
|
||||||
|
|||||||
@@ -174,21 +174,6 @@ public class CraftingTaskNormal implements ICraftingTask {
|
|||||||
return pattern;
|
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
|
@Override
|
||||||
public List<IProcessable> getToProcess() {
|
public List<IProcessable> getToProcess() {
|
||||||
return toProcess;
|
return toProcess;
|
||||||
|
|||||||
Reference in New Issue
Block a user