Add more docs + remove unneeded methods from interface

This commit is contained in:
Raoul Van den Berge
2016-06-25 21:10:37 +02:00
parent 75e53294de
commit 5b3cde7675
12 changed files with 90 additions and 74 deletions

View File

@@ -18,6 +18,8 @@ import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.network.INetworkMaster;
import refinedstorage.api.storage.CompareFlags;
import refinedstorage.item.ItemUpgrade;
@@ -295,4 +297,12 @@ public final class RefinedStorageUtils {
}
}
}
public static ItemStack takeFromNetwork(INetworkMaster network, ItemStack stack, int size) {
return network.take(stack, size, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
}
public static ICraftingPattern getPatternFromNetwork(INetworkMaster network, ItemStack stack) {
return network.getPattern(stack, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
}
}

View File

@@ -1,19 +1,10 @@
package refinedstorage.api.network;
/**
* Flags for knowing what pull action the player is performing, can be combined.
*/
public class GridPullFlags {
public static final int PULL_HALF = 1;
public static final int PULL_ONE = 2;
public static final int PULL_SHIFT = 4;
public static boolean isPullingHalf(int flags) {
return (flags & PULL_HALF) == PULL_HALF;
}
public static boolean isPullingOne(int flags) {
return (flags & PULL_ONE) == PULL_ONE;
}
public static boolean isPullingWithShift(int flags) {
return (flags & PULL_SHIFT) == PULL_SHIFT;
}
}

View File

@@ -63,7 +63,7 @@ public interface INetworkMaster {
List<ItemStack> getItems();
/**
* @return The crafting tasks in this, do NOT modify this list
* @return The crafting tasks in this network, do NOT modify this list
*/
List<ICraftingTask> getCraftingTasks();
@@ -82,10 +82,10 @@ public interface INetworkMaster {
void addCraftingTaskAsLast(ICraftingTask task);
/**
* Creates a crafting task from a pattern
* Creates a crafting task from a pattern.
*
* @param pattern The pattern to create a task for
* @return The task
* @return A task
*/
ICraftingTask createCraftingTask(ICraftingPattern pattern);
@@ -97,7 +97,7 @@ public interface INetworkMaster {
void cancelCraftingTask(ICraftingTask task);
/**
* @return A list of crafting patterns in this network
* @return A list of crafting patterns in this network, do NOT modify this list
*/
List<ICraftingPattern> getPatterns();
@@ -105,27 +105,17 @@ public interface INetworkMaster {
* Returns crafting patterns from an item stack.
*
* @param pattern The item to get a pattern for
* @param flags The flags we compare on
* @param flags The flags to compare on, see {@link CompareFlags}
* @return A list of crafting patterns where the given pattern is one of the outputs
*/
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 {@link ItemStack} to get a pattern for
* @return The pattern
*/
ICraftingPattern getPatternWithBestScore(ItemStack pattern);
List<ICraftingPattern> getPatterns(ItemStack pattern, int flags);
/**
* @param pattern The {@link ItemStack} to get a pattern for
* @param flags The flags we compare on, see {@link CompareFlags}
* @param flags The flags to compare on, see {@link CompareFlags}
* @return The pattern
*/
ICraftingPattern getPatternWithBestScore(ItemStack pattern, int flags);
ICraftingPattern getPattern(ItemStack pattern, int flags);
/**
* Sends to all clients in a grid a packet with all the items in this network.
@@ -148,30 +138,21 @@ public interface INetworkMaster {
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.
* Takes an item from this network.
*
* @param stack A prototype of the stack to take, do NOT modify
* @param stack A prototype of the stack to takeFromNetwork, 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);
/**
* @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
* @param flags The flags to compare on, see {@link CompareFlags}
* @return null if we didn't takeFromNetwork 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 {@link ItemStack} we found
* @param stack The stack prototype to search
* @param flags The flags to compare on, see {@link CompareFlags}
* @return The {@link ItemStack} we found, do NOT modify
*/
@Nullable
ItemStack getItem(ItemStack stack, int flags);

View File

@@ -3,18 +3,59 @@ package refinedstorage.api.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHand;
import javax.annotation.Nullable;
/**
* Defines behaviour of wireless grids.
*/
public interface IWirelessGridHandler {
/**
* Called every network tick.
*/
void update();
/**
* Called when a player opens a wireless grid.
*
* @param player The player that opened the wireless grid
* @param hand The hand the player opened it with
* @return If the opening was successful
*/
boolean onOpen(EntityPlayer player, EnumHand hand);
/**
* Called when the player closes a wireless grid.
*
* @param player The player that closed the grid
*/
void onClose(EntityPlayer player);
/**
* Sets the range of the wireless grid handler.
*
* @param range The range
*/
void setRange(int range);
/**
* @return The range wireless grids in this network can reach
*/
int getRange();
/**
* Drains energy from the wireless grid of a player.
*
* @param player The player to drain energy from
* @param energy The amount of energy that has to be drained
*/
void drainEnergy(EntityPlayer player, int energy);
/**
* Returns a {@link WirelessGridConsumer} for a player.
*
* @param player The player to get the wireless grid consumer for
* @return The wireless grid consumer of the player, or null if the player isn't in a wireless grid
*/
@Nullable
WirelessGridConsumer getConsumer(EntityPlayer player);
}

View File

@@ -4,6 +4,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
/**
* Represents a player using a wireless grid.
*/
public class WirelessGridConsumer {
private EntityPlayer player;
private EnumHand hand;

View File

@@ -7,7 +7,7 @@ import javax.annotation.Nullable;
import java.util.List;
/**
* The recipe registry of the solderer.
* The recipe registry of the solderer, access it via {@link refinedstorage.api.RefinedStorageAPI#SOLDERER_REGISTRY}.
*/
public interface ISoldererRegistry {
/**

View File

@@ -33,10 +33,10 @@ public interface IStorage {
* 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 stack A prototype of the stack to takeFromNetwork, 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
* @param flags On what we are comparing to takeFromNetwork the item, see {@link CompareFlags}
* @return null if we didn't takeFromNetwork anything, or a {@link ItemStack} with the result
*/
ItemStack take(@Nonnull ItemStack stack, int size, int flags);

View File

@@ -67,14 +67,14 @@ public class BasicCraftingTask implements ICraftingTask {
if (!satisfied[i]) {
done = false;
ItemStack took = network.take(input, 1);
ItemStack took = RefinedStorageUtils.takeFromNetwork(network, input, 1);
if (took != null) {
itemsTook.add(took);
satisfied[i] = true;
} else if (!childTasks[i]) {
ICraftingPattern pattern = network.getPatternWithBestScore(input);
ICraftingPattern pattern = RefinedStorageUtils.getPatternFromNetwork(network, input);
if (pattern != null) {
network.addCraftingTask(network.createCraftingTask(pattern));

View File

@@ -16,7 +16,7 @@ public class CraftingTaskScheduler {
}
public void schedule(INetworkMaster network, int compare, ItemStack item) {
ICraftingPattern pattern = network.getPatternWithBestScore(item, compare);
ICraftingPattern pattern = network.getPattern(item, compare);
if (pattern != null) {
scheduledItem = item;

View File

@@ -52,7 +52,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
for (int i = 0; i < inserted.length; ++i) {
if (!inserted[i]) {
ItemStack input = pattern.getInputs()[i];
ItemStack took = network.take(input, 1);
ItemStack took = RefinedStorageUtils.takeFromNetwork(network, input, 1);
if (took != null) {
if (ItemHandlerHelper.insertItem(container.getConnectedItems(), took, true) == null) {
@@ -63,7 +63,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
network.push(took, took.stackSize, false);
}
} else if (!childTasks[i]) {
ICraftingPattern pattern = network.getPatternWithBestScore(input);
ICraftingPattern pattern = RefinedStorageUtils.getPatternFromNetwork(network, input);
if (pattern != null) {
childTasks[i] = true;

View File

@@ -29,21 +29,21 @@ public class GridHandler implements IGridHandler {
int size = 64;
if (GridPullFlags.isPullingHalf(flags) && stack.stackSize > 1) {
if ((flags & GridPullFlags.PULL_HALF) == GridPullFlags.PULL_HALF && stack.stackSize > 1) {
size = stack.stackSize / 2;
if (size > 32) {
size = 32;
}
} else if (GridPullFlags.isPullingOne(flags)) {
} else if ((flags & GridPullFlags.PULL_ONE) == GridPullFlags.PULL_ONE) {
size = 1;
} else if (GridPullFlags.isPullingWithShift(flags)) {
} else if ((flags & GridPullFlags.PULL_SHIFT) == GridPullFlags.PULL_SHIFT) {
// NO OP, the quantity already set (64) is needed for shift
}
size = Math.min(size, stack.getItem().getItemStackLimit(stack));
ItemStack took = network.take(stack, size);
ItemStack took = RefinedStorageUtils.takeFromNetwork(network, stack, size);
// Fallback for corner cases where NBT changes
if (took == null) {
@@ -51,7 +51,7 @@ public class GridHandler implements IGridHandler {
}
if (took != null) {
if (GridPullFlags.isPullingWithShift(flags)) {
if ((flags & GridPullFlags.PULL_SHIFT) == GridPullFlags.PULL_SHIFT) {
if (!player.inventory.addItemStackToInventory(took.copy())) {
InventoryHelper.spawnItemStack(player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ(), took);
}
@@ -105,7 +105,7 @@ public class GridHandler implements IGridHandler {
int quantityPerRequest = 0;
ICraftingPattern pattern = network.getPatternWithBestScore(stack);
ICraftingPattern pattern = RefinedStorageUtils.getPatternFromNetwork(network, stack);
if (pattern != null) {
for (ItemStack output : pattern.getOutputs()) {

View File

@@ -295,7 +295,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
}
@Override
public List<ICraftingPattern> getPattern(ItemStack pattern, int flags) {
public List<ICraftingPattern> getPatterns(ItemStack pattern, int flags) {
List<ICraftingPattern> patterns = new ArrayList<ICraftingPattern>();
for (ICraftingPattern craftingPattern : getPatterns()) {
@@ -310,13 +310,8 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
}
@Override
public ICraftingPattern getPatternWithBestScore(ItemStack pattern) {
return getPatternWithBestScore(pattern, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
}
@Override
public ICraftingPattern getPatternWithBestScore(ItemStack pattern, int flags) {
List<ICraftingPattern> patterns = getPattern(pattern, flags);
public ICraftingPattern getPattern(ItemStack pattern, int flags) {
List<ICraftingPattern> patterns = getPatterns(pattern, flags);
if (patterns.isEmpty()) {
return null;
@@ -517,11 +512,6 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
return remainder;
}
@Override
public ItemStack take(ItemStack stack, int size) {
return take(stack, size, CompareFlags.COMPARE_DAMAGE | CompareFlags.COMPARE_NBT);
}
@Override
public ItemStack take(ItemStack stack, int size, int flags) {
int requested = size;