Add docs for INetworkMaster

This commit is contained in:
Raoul Van den Berge
2016-06-23 01:36:03 +02:00
parent 4c8d1527f6
commit 800903b227
5 changed files with 143 additions and 5 deletions

View File

@@ -5,5 +5,5 @@ import net.minecraftforge.items.IItemHandler;
public interface ICraftingPatternContainer { public interface ICraftingPatternContainer {
int getSpeed(); int getSpeed();
IItemHandler getConnectedInventory(); IItemHandler getConnectedItems();
} }

View File

@@ -8,65 +8,201 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import refinedstorage.api.autocrafting.ICraftingPattern; import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingTask; import refinedstorage.api.autocrafting.ICraftingTask;
import refinedstorage.api.storage.CompareFlags;
import javax.annotation.Nullable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
public interface INetworkMaster { public interface INetworkMaster {
/**
* @return The world this network is in
*/
World getWorld(); World getWorld();
/**
* Initializes this network.
* Starting from this call {@link INetworkMaster#update()} will be called every server tick.
*
* @param world The world this network is in
*/
void setWorld(World world); void setWorld(World world);
/**
* @return The energy storage of this network
*/
EnergyStorage getEnergy(); EnergyStorage getEnergy();
/**
* @return The energy usage of this network
*/
int getEnergyUsage(); int getEnergyUsage();
/**
* @return The position of this network in the world (usually where the controller is)
*/
BlockPos getPosition(); BlockPos getPosition();
/**
* @return If this network is able to run (usually corresponds to redstone setting)
*/
boolean canRun(); boolean canRun();
/**
* Updates this network.
*/
void update(); void update();
/**
* @return A iterator with all network slaves
*/
Iterator<INetworkSlave> getSlaves(); Iterator<INetworkSlave> getSlaves();
/**
* @param slave The slave to add
*/
void addSlave(BlockPos slave); void addSlave(BlockPos slave);
/**
* @param slave The slave to remove
*/
void removeSlave(BlockPos slave); void removeSlave(BlockPos slave);
/**
* @return The grid handler for this network
*/
IGridHandler getGridHandler(); IGridHandler getGridHandler();
/**
* @return The wireless grid handler for this network
*/
IWirelessGridHandler getWirelessGridHandler(); IWirelessGridHandler getWirelessGridHandler();
/**
* @return The items stored in this network, do NOT modify this list
*/
List<ItemStack> getItems(); List<ItemStack> getItems();
/**
* @return The crafting tasks in this, do NOT modify this list
*/
List<ICraftingTask> getCraftingTasks(); List<ICraftingTask> getCraftingTasks();
/**
* Adds a crafting task to the top of the crafting task stack.
*
* @param task The crafting task to add
*/
void addCraftingTask(ICraftingTask task); void addCraftingTask(ICraftingTask task);
/**
* Adds a crafting task to the bottom of the crafting task stack.
*
* @param task The crafting task to add
*/
void addCraftingTaskAsLast(ICraftingTask task); void addCraftingTaskAsLast(ICraftingTask task);
/**
* Creates a crafting task from a pattern
*
* @param pattern The pattern to create a task for
* @return The task
*/
ICraftingTask createCraftingTask(ICraftingPattern pattern); ICraftingTask createCraftingTask(ICraftingPattern pattern);
/**
* Cancels a crafting task.
*
* @param task The task to cancel
*/
void cancelCraftingTask(ICraftingTask task); void cancelCraftingTask(ICraftingTask task);
/**
* @return A list of crafting patterns in this network
*/
List<ICraftingPattern> getPatterns(); List<ICraftingPattern> getPatterns();
/**
* Returns crafting patterns from an item stack.
*
* @param pattern The item to get a pattern for
* @param flags The flags we compare on
* @return A list of crafting patterns where the given pattern is one of the outputs
*/
List<ICraftingPattern> getPattern(ItemStack pattern, int flags); List<ICraftingPattern> getPattern(ItemStack pattern, int flags);
/**
* Returns a crafting pattern from an item stack.
* If there are multiple crafting patterns with the same output, it'll return the one
* where there are the most ingredients of in the network.
*
* @param pattern The item to get a pattern for
* @return The pattern
*/
ICraftingPattern getPatternWithBestScore(ItemStack pattern); ICraftingPattern getPatternWithBestScore(ItemStack pattern);
/**
* Returns a crafting pattern from an item stack.
* If there are multiple crafting patterns with the same output, it'll return the one
* where there are the most ingredients of in the network.
*
* @param pattern The item to get a pattern for
* @param flags The flags we compare on
* @return The pattern
*/
ICraftingPattern getPatternWithBestScore(ItemStack pattern, int flags); ICraftingPattern getPatternWithBestScore(ItemStack pattern, int flags);
/**
* Sends to all clients watching a network (for example a grid) a packet with all the items in this network.
*/
void updateItemsWithClient(); void updateItemsWithClient();
/**
* Sends a player a packet with all the items in this network.
*/
void updateItemsWithClient(EntityPlayerMP player); void updateItemsWithClient(EntityPlayerMP player);
/**
* Pushes an item to this network.
*
* @param stack The stack prototype to push, do NOT modify
* @param size The amount of that prototype that has to be pushed
* @param simulate If we are simulating
* @return null if the push was successful, or a {@link ItemStack} with the remainder
*/
ItemStack push(ItemStack stack, int size, boolean simulate); ItemStack push(ItemStack stack, int size, boolean simulate);
/**
* Takes an item from storage.
* If the stack we found in the system is smaller than the requested size, return the stack anyway.
* For example: this method is called for dirt (64x) while there is only dirt (32x), return the dirt (32x) anyway.
*
* @param stack A prototype of the stack to take, do NOT modify
* @param size The amount of that prototype that has to be taken
* @return null if we didn't take anything, or a {@link ItemStack} with the result
*/
ItemStack take(ItemStack stack, int size); ItemStack take(ItemStack stack, int size);
/**
* Takes an item from storage.
* If the stack we found in the system is smaller than the requested size, return the stack anyway.
* For example: this method is called for dirt (64x) while there is only dirt (32x), return the dirt (32x) anyway.
*
* @param stack A prototype of the stack to take, do NOT modify
* @param size The amount of that prototype that has to be taken
* @param flags On what we are comparing to take the item, see {@link CompareFlags}
* @return null if we didn't take anything, or a {@link ItemStack} with the result
*/
ItemStack take(ItemStack stack, int size, int flags); ItemStack take(ItemStack stack, int size, int flags);
/**
* Returns an item from storage, based on the given prototype.
*
* @param stack The stack to search
* @param flags The flags to compare on
* @return The stack we found
*/
@Nullable
ItemStack getItem(ItemStack stack, int flags); ItemStack getItem(ItemStack stack, int flags);
NBTTagCompound writeToNBT(NBTTagCompound tag); NBTTagCompound writeToNBT(NBTTagCompound tag);

View File

@@ -9,6 +9,8 @@ import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
// @todo: Non API import
/** /**
* The recipe registry of the solderer. * The recipe registry of the solderer.
*/ */

View File

@@ -47,15 +47,15 @@ public class ProcessingCraftingTask implements ICraftingTask {
ICraftingPatternContainer container = pattern.getContainer(network.getWorld()); ICraftingPatternContainer container = pattern.getContainer(network.getWorld());
if (container.getConnectedInventory() != null) { if (container.getConnectedItems() != null) {
for (int i = 0; i < inserted.length; ++i) { for (int i = 0; i < inserted.length; ++i) {
if (!inserted[i]) { if (!inserted[i]) {
ItemStack input = pattern.getInputs()[i]; ItemStack input = pattern.getInputs()[i];
ItemStack took = network.take(input, 1); ItemStack took = network.take(input, 1);
if (took != null) { if (took != null) {
if (ItemHandlerHelper.insertItem(container.getConnectedInventory(), took, true) == null) { if (ItemHandlerHelper.insertItem(container.getConnectedItems(), took, true) == null) {
ItemHandlerHelper.insertItem(container.getConnectedInventory(), took, false); ItemHandlerHelper.insertItem(container.getConnectedItems(), took, false);
inserted[i] = true; inserted[i] = true;
} else { } else {

View File

@@ -79,7 +79,7 @@ public class TileCrafter extends TileSlave implements ICraftingPatternContainer
} }
@Override @Override
public IItemHandler getConnectedInventory() { public IItemHandler getConnectedItems() {
return RefinedStorageUtils.getItemHandler(getFacingTile(), getDirection().getOpposite()); return RefinedStorageUtils.getItemHandler(getFacingTile(), getDirection().getOpposite());
} }