diff --git a/src/main/java/refinedstorage/api/autocrafting/ICraftingPatternContainer.java b/src/main/java/refinedstorage/api/autocrafting/ICraftingPatternContainer.java index 594b5ddf3..26c82ca3a 100755 --- a/src/main/java/refinedstorage/api/autocrafting/ICraftingPatternContainer.java +++ b/src/main/java/refinedstorage/api/autocrafting/ICraftingPatternContainer.java @@ -5,5 +5,5 @@ import net.minecraftforge.items.IItemHandler; public interface ICraftingPatternContainer { int getSpeed(); - IItemHandler getConnectedInventory(); + IItemHandler getConnectedItems(); } diff --git a/src/main/java/refinedstorage/api/network/INetworkMaster.java b/src/main/java/refinedstorage/api/network/INetworkMaster.java index 619362562..944d379b5 100755 --- a/src/main/java/refinedstorage/api/network/INetworkMaster.java +++ b/src/main/java/refinedstorage/api/network/INetworkMaster.java @@ -8,65 +8,201 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import refinedstorage.api.autocrafting.ICraftingPattern; import refinedstorage.api.autocrafting.ICraftingTask; +import refinedstorage.api.storage.CompareFlags; +import javax.annotation.Nullable; import java.util.Iterator; import java.util.List; public interface INetworkMaster { + /** + * @return The world this network is in + */ 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); + /** + * @return The energy storage of this network + */ EnergyStorage getEnergy(); + /** + * @return The energy usage of this network + */ int getEnergyUsage(); + /** + * @return The position of this network in the world (usually where the controller is) + */ BlockPos getPosition(); + /** + * @return If this network is able to run (usually corresponds to redstone setting) + */ boolean canRun(); + /** + * Updates this network. + */ void update(); + /** + * @return A iterator with all network slaves + */ Iterator getSlaves(); + /** + * @param slave The slave to add + */ void addSlave(BlockPos slave); + /** + * @param slave The slave to remove + */ void removeSlave(BlockPos slave); + /** + * @return The grid handler for this network + */ IGridHandler getGridHandler(); + /** + * @return The wireless grid handler for this network + */ IWirelessGridHandler getWirelessGridHandler(); + /** + * @return The items stored in this network, do NOT modify this list + */ List getItems(); + /** + * @return The crafting tasks in this, do NOT modify this list + */ List getCraftingTasks(); + /** + * Adds a crafting task to the top of the crafting task stack. + * + * @param task The crafting task to add + */ 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); + /** + * Creates a crafting task from a pattern + * + * @param pattern The pattern to create a task for + * @return The task + */ ICraftingTask createCraftingTask(ICraftingPattern pattern); + /** + * Cancels a crafting task. + * + * @param task The task to cancel + */ void cancelCraftingTask(ICraftingTask task); + /** + * @return A list of crafting patterns in this network + */ List 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 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); + /** + * 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); + /** + * Sends to all clients watching a network (for example a grid) a packet with all the items in this network. + */ void updateItemsWithClient(); + /** + * Sends a player a packet with all the items in this network. + */ 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); + /** + * 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); + /** + * 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); + /** + * 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); NBTTagCompound writeToNBT(NBTTagCompound tag); diff --git a/src/main/java/refinedstorage/api/solderer/SoldererRegistry.java b/src/main/java/refinedstorage/api/solderer/SoldererRegistry.java index 5bc187c8a..eeaa73e2f 100755 --- a/src/main/java/refinedstorage/api/solderer/SoldererRegistry.java +++ b/src/main/java/refinedstorage/api/solderer/SoldererRegistry.java @@ -9,6 +9,8 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +// @todo: Non API import + /** * The recipe registry of the solderer. */ diff --git a/src/main/java/refinedstorage/apiimpl/autocrafting/ProcessingCraftingTask.java b/src/main/java/refinedstorage/apiimpl/autocrafting/ProcessingCraftingTask.java index a0647c0ed..d2ab1c273 100755 --- a/src/main/java/refinedstorage/apiimpl/autocrafting/ProcessingCraftingTask.java +++ b/src/main/java/refinedstorage/apiimpl/autocrafting/ProcessingCraftingTask.java @@ -47,15 +47,15 @@ public class ProcessingCraftingTask implements ICraftingTask { ICraftingPatternContainer container = pattern.getContainer(network.getWorld()); - if (container.getConnectedInventory() != null) { + if (container.getConnectedItems() != null) { for (int i = 0; i < inserted.length; ++i) { if (!inserted[i]) { ItemStack input = pattern.getInputs()[i]; ItemStack took = network.take(input, 1); if (took != null) { - if (ItemHandlerHelper.insertItem(container.getConnectedInventory(), took, true) == null) { - ItemHandlerHelper.insertItem(container.getConnectedInventory(), took, false); + if (ItemHandlerHelper.insertItem(container.getConnectedItems(), took, true) == null) { + ItemHandlerHelper.insertItem(container.getConnectedItems(), took, false); inserted[i] = true; } else { diff --git a/src/main/java/refinedstorage/tile/TileCrafter.java b/src/main/java/refinedstorage/tile/TileCrafter.java index b0b1474e6..8e9ad5a0f 100755 --- a/src/main/java/refinedstorage/tile/TileCrafter.java +++ b/src/main/java/refinedstorage/tile/TileCrafter.java @@ -79,7 +79,7 @@ public class TileCrafter extends TileSlave implements ICraftingPatternContainer } @Override - public IItemHandler getConnectedInventory() { + public IItemHandler getConnectedItems() { return RefinedStorageUtils.getItemHandler(getFacingTile(), getDirection().getOpposite()); }