Added documentation for the new API

This commit is contained in:
raoulvdberge
2017-07-18 19:32:46 +02:00
parent a926ca0803
commit e76b389b25
12 changed files with 225 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftin
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElementRegistry; import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElementRegistry;
import com.raoulvdberge.refinedstorage.api.autocrafting.registry.ICraftingTaskRegistry; import com.raoulvdberge.refinedstorage.api.autocrafting.registry.ICraftingTaskRegistry;
import com.raoulvdberge.refinedstorage.api.network.INetwork; import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.network.grid.wireless.IWirelessGridFactory;
import com.raoulvdberge.refinedstorage.api.network.grid.wireless.IWirelessGridRegistry; import com.raoulvdberge.refinedstorage.api.network.grid.wireless.IWirelessGridRegistry;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
@@ -109,9 +110,20 @@ public interface IRSAPI {
@Nonnull @Nonnull
ICraftingMonitorElementList createCraftingMonitorElementList(); ICraftingMonitorElementList createCraftingMonitorElementList();
/**
* @return the wireless grid registry
*/
@Nonnull @Nonnull
IWirelessGridRegistry getWirelessGridRegistry(); IWirelessGridRegistry getWirelessGridRegistry();
/**
* Opens a wireless grid for the given player.
*
* @param player the player
* @param hand the hand where the wireless grid is in
* @param networkDimension the dimension of the bound network
* @param id the id of the wireless grid, as returned in {@link IWirelessGridRegistry#add(IWirelessGridFactory)}
*/
void openWirelessGrid(EntityPlayer player, EnumHand hand, int networkDimension, int id); void openWirelessGrid(EntityPlayer player, EnumHand hand, int networkDimension, int id);
/** /**

View File

@@ -2,10 +2,26 @@ package com.raoulvdberge.refinedstorage.api.network.grid;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.IStringSerializable;
/**
* Represents a grid type.
* Used in {@link IGrid} to determine grid GUI rendering.
*/
public enum GridType implements IStringSerializable { public enum GridType implements IStringSerializable {
/**
* A regular grid.
*/
NORMAL(0, "normal"), NORMAL(0, "normal"),
/**
* A crafting grid.
*/
CRAFTING(1, "crafting"), CRAFTING(1, "crafting"),
/**
* A pattern grid.
*/
PATTERN(2, "pattern"), PATTERN(2, "pattern"),
/**
* A fluid grid.
*/
FLUID(3, "fluid"); FLUID(3, "fluid");
private int id; private int id;

View File

@@ -13,67 +13,165 @@ import net.minecraftforge.items.IItemHandlerModifiable;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
/**
* Represents a grid.
*/
public interface IGrid { public interface IGrid {
/**
* @return the grid type
*/
GridType getType(); GridType getType();
/**
* @return the network of this grid, or null if the network is unavailable
*/
@Nullable @Nullable
INetwork getNetwork(); INetwork getNetwork();
/**
* @return the item grid handler of the network of the grid, or null if the network is unavailable
*/
@Nullable @Nullable
default IItemGridHandler getItemHandler() { default IItemGridHandler getItemHandler() {
return getNetwork() != null ? getNetwork().getItemGridHandler() : null; return getNetwork() != null ? getNetwork().getItemGridHandler() : null;
} }
/**
* @return the fluid grid handler of the network of the grid, or null if the network is unavailable
*/
@Nullable @Nullable
default IFluidGridHandler getFluidHandler() { default IFluidGridHandler getFluidHandler() {
return getNetwork() != null ? getNetwork().getFluidGridHandler() : null; return getNetwork() != null ? getNetwork().getFluidGridHandler() : null;
} }
/**
* @return an unlocalized gui title
*/
String getGuiTitle(); String getGuiTitle();
/**
* @return the view type
*/
int getViewType(); int getViewType();
/**
* @return the sorting type
*/
int getSortingType(); int getSortingType();
/**
* @return the sorting direction
*/
int getSortingDirection(); int getSortingDirection();
/**
* @return the search box mode
*/
int getSearchBoxMode(); int getSearchBoxMode();
/**
* @return the current tab that is selected
*/
int getTabSelected(); int getTabSelected();
/**
* @return the size mode
*/
int getSize(); int getSize();
/**
* @param type the new view type
*/
void onViewTypeChanged(int type); void onViewTypeChanged(int type);
/**
* @param type the new sorting type
*/
void onSortingTypeChanged(int type); void onSortingTypeChanged(int type);
/**
* @param direction the new direction
*/
void onSortingDirectionChanged(int direction); void onSortingDirectionChanged(int direction);
/**
* @param searchBoxMode the new search box mode
*/
void onSearchBoxModeChanged(int searchBoxMode); void onSearchBoxModeChanged(int searchBoxMode);
/**
* @param size the new size mode
*/
void onSizeChanged(int size); void onSizeChanged(int size);
/**
* @param tab the new selected tab
*/
void onTabSelectionChanged(int tab); void onTabSelectionChanged(int tab);
/**
* @return the filters
*/
List<IFilter> getFilters(); List<IFilter> getFilters();
/**
* @return the tabs
*/
List<IGridTab> getTabs(); List<IGridTab> getTabs();
/**
* @return the inventory of the filters
*/
IItemHandlerModifiable getFilter(); IItemHandlerModifiable getFilter();
/**
* @return the crafting matrix, or null if not a crafting grid
*/
@Nullable
InventoryCrafting getCraftingMatrix(); InventoryCrafting getCraftingMatrix();
/**
* @return the crafting result inventory, or null if not a crafting grid
*/
@Nullable
InventoryCraftResult getCraftingResult(); InventoryCraftResult getCraftingResult();
/**
* Called when the crafting matrix changes.
*/
void onCraftingMatrixChanged(); void onCraftingMatrixChanged();
/**
* Called when an item is crafted in a crafting grid.
*
* @param player the player that crafted the item
*/
void onCrafted(EntityPlayer player); void onCrafted(EntityPlayer player);
/**
* Called when an item is crafted with shift click (up to 64 items) in a crafting grid.
*
* @param player the player that crafted the item
*/
void onCraftedShift(EntityPlayer player); void onCraftedShift(EntityPlayer player);
/**
* Called when a JEI recipe transfer occurs.
*
* @param player the player
* @param recipe a 9*x array stack array, where x is the possible combinations for the given slot
*/
void onRecipeTransfer(EntityPlayer player, ItemStack[][] recipe); void onRecipeTransfer(EntityPlayer player, ItemStack[][] recipe);
/**
* Called when the grid is closed.
*
* @param player the player
*/
void onClosed(EntityPlayer player); void onClosed(EntityPlayer player);
/**
* @return true if the grid is active, false otherwise
*/
boolean isActive(); boolean isActive();
} }

View File

@@ -5,10 +5,22 @@ import net.minecraft.item.ItemStack;
import java.util.List; import java.util.List;
/**
* Represents a grid tab.
*/
public interface IGridTab { public interface IGridTab {
/**
* @return the filters
*/
List<IFilter> getFilters(); List<IFilter> getFilters();
/**
* @return the name
*/
String getName(); String getName();
/**
* @return the icon
*/
ItemStack getIcon(); ItemStack getIcon();
} }

View File

@@ -6,7 +6,18 @@ import net.minecraft.util.EnumHand;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
/**
* A factory interface for a wireless grid.
*/
public interface IWirelessGridFactory { public interface IWirelessGridFactory {
/**
* Creates a new wireless grid.
*
* @param player the player
* @param hand the hand
* @param networkDimension the network dimension of the grid
* @return the grid
*/
@Nonnull @Nonnull
IGrid create(EntityPlayer player, EnumHand hand, int networkDimension); IGrid create(EntityPlayer player, EnumHand hand, int networkDimension);
} }

View File

@@ -1,10 +1,28 @@
package com.raoulvdberge.refinedstorage.api.network.grid.wireless; package com.raoulvdberge.refinedstorage.api.network.grid.wireless;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHand;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/**
* A registry for wireless grid factories.
*/
public interface IWirelessGridRegistry { public interface IWirelessGridRegistry {
/**
* Registers a new wireless grid factory.
*
* @param factory the factory
* @return the id of this new wireless grid, use this id in {@link com.raoulvdberge.refinedstorage.api.IRSAPI#openWirelessGrid(EntityPlayer, EnumHand, int, int)}.
*/
int add(IWirelessGridFactory factory); int add(IWirelessGridFactory factory);
/**
* Gets a wireless grid factory by id.
*
* @param id the id, as returned by {@link #add(IWirelessGridFactory)}
* @return the wireless grid factory, or null if none is found
*/
@Nullable @Nullable
IWirelessGridFactory get(int id); IWirelessGridFactory get(int id);
} }

View File

@@ -25,5 +25,10 @@ public interface INetworkItem {
*/ */
boolean onOpen(INetwork network, EntityPlayer player, EnumHand hand); boolean onOpen(INetwork network, EntityPlayer player, EnumHand hand);
/**
* Called when an action occurs that is defined in {@link NetworkItemAction} and the network item is in use.
*
* @param action the action
*/
void onAction(NetworkItemAction action); void onAction(NetworkItemAction action);
} }

View File

@@ -1,11 +1,36 @@
package com.raoulvdberge.refinedstorage.api.network.item; package com.raoulvdberge.refinedstorage.api.network.item;
/**
* Represents an network item action.
* Called with {@link INetworkItem#onAction(NetworkItemAction)}.
*/
public enum NetworkItemAction { public enum NetworkItemAction {
/**
* Used when an item is inserted in a grid.
*/
ITEM_INSERTED, ITEM_INSERTED,
/**
* Used when an item is extracted in a grid.
*/
ITEM_EXTRACTED, ITEM_EXTRACTED,
/**
* Used when an item is crafted in a crafting grid (regular crafting, not autocrafting).
*/
ITEM_CRAFTED, ITEM_CRAFTED,
/**
* Used when a fluid is inserted in a grid.
*/
FLUID_INSERTED, FLUID_INSERTED,
/**
* Used when a fluid is extracted in a grid.
*/
FLUID_EXTRACTED, FLUID_EXTRACTED,
/**
* Used when a crafting task is cancelled in a crafting monitor.
*/
CRAFTING_TASK_CANCELLED, CRAFTING_TASK_CANCELLED,
/**
* Used when all crafting tasks are cancelled in a crafting monitor.
*/
CRAFTING_TASK_ALL_CANCELLED CRAFTING_TASK_ALL_CANCELLED
} }

View File

@@ -2,12 +2,30 @@ package com.raoulvdberge.refinedstorage.api.util;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
/**
* A filter.
*/
public interface IFilter { public interface IFilter {
int MODE_WHITELIST = 0;
int MODE_BLACKLIST = 1;
/**
* @return the stack being filtered
*/
ItemStack getStack(); ItemStack getStack();
/**
* @return the compare flags, see {@link IComparer}
*/
int getCompare(); int getCompare();
/**
* @return the mode, whitelist or blacklist
*/
int getMode(); int getMode();
/**
* @return true if this is a mod filter, false otherwise
*/
boolean isModFilter(); boolean isModFilter();
} }

View File

@@ -2,6 +2,7 @@ package com.raoulvdberge.refinedstorage.gui;
import com.raoulvdberge.refinedstorage.RS; import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.api.util.IFilter;
import com.raoulvdberge.refinedstorage.container.ContainerFilter; import com.raoulvdberge.refinedstorage.container.ContainerFilter;
import com.raoulvdberge.refinedstorage.item.ItemFilter; import com.raoulvdberge.refinedstorage.item.ItemFilter;
import com.raoulvdberge.refinedstorage.network.MessageFilterUpdate; import com.raoulvdberge.refinedstorage.network.MessageFilterUpdate;
@@ -51,7 +52,7 @@ public class GuiFilter extends GuiBase {
} }
private void updateModeButton(int mode) { private void updateModeButton(int mode) {
String text = mode == ItemFilter.MODE_WHITELIST ? t("sidebutton.refinedstorage:mode.whitelist") : t("sidebutton.refinedstorage:mode.blacklist"); String text = mode == IFilter.MODE_WHITELIST ? t("sidebutton.refinedstorage:mode.whitelist") : t("sidebutton.refinedstorage:mode.blacklist");
toggleMode.setWidth(fontRenderer.getStringWidth(text) + 12); toggleMode.setWidth(fontRenderer.getStringWidth(text) + 12);
toggleMode.displayString = text; toggleMode.displayString = text;
@@ -104,7 +105,7 @@ public class GuiFilter extends GuiBase {
} else if (button == compareOredict) { } else if (button == compareOredict) {
compare ^= IComparer.COMPARE_OREDICT; compare ^= IComparer.COMPARE_OREDICT;
} else if (button == toggleMode) { } else if (button == toggleMode) {
mode = mode == ItemFilter.MODE_WHITELIST ? ItemFilter.MODE_BLACKLIST : ItemFilter.MODE_WHITELIST; mode = mode == IFilter.MODE_WHITELIST ? IFilter.MODE_BLACKLIST : IFilter.MODE_WHITELIST;
updateModeButton(mode); updateModeButton(mode);
} else if (button == toggleModFilter) { } else if (button == toggleModFilter) {

View File

@@ -4,7 +4,6 @@ import com.raoulvdberge.refinedstorage.api.util.IFilter;
import com.raoulvdberge.refinedstorage.apiimpl.API; import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.gui.grid.stack.GridStackItem; import com.raoulvdberge.refinedstorage.gui.grid.stack.GridStackItem;
import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack; import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack;
import com.raoulvdberge.refinedstorage.item.ItemFilter;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import java.util.List; import java.util.List;
@@ -27,20 +26,20 @@ public class GridFilterFilter implements Predicate<IGridStack> {
return true; return true;
} }
int lastMode = ItemFilter.MODE_WHITELIST; int lastMode = IFilter.MODE_WHITELIST;
for (IFilter filter : filters) { for (IFilter filter : filters) {
lastMode = filter.getMode(); lastMode = filter.getMode();
if (filter.isModFilter()) { if (filter.isModFilter()) {
if (filter.getStack().getItem().getRegistryName().getResourceDomain().equalsIgnoreCase(stackModId)) { if (filter.getStack().getItem().getRegistryName().getResourceDomain().equalsIgnoreCase(stackModId)) {
return filter.getMode() == ItemFilter.MODE_WHITELIST; return filter.getMode() == IFilter.MODE_WHITELIST;
} }
} else if (API.instance().getComparer().isEqual(stack, filter.getStack(), filter.getCompare())) { } else if (API.instance().getComparer().isEqual(stack, filter.getStack(), filter.getCompare())) {
return filter.getMode() == ItemFilter.MODE_WHITELIST; return filter.getMode() == IFilter.MODE_WHITELIST;
} }
} }
return lastMode != ItemFilter.MODE_WHITELIST; return lastMode != IFilter.MODE_WHITELIST;
} }
} }

View File

@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSGui; import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.RSItems; import com.raoulvdberge.refinedstorage.RSItems;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.api.util.IFilter;
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFilterItems; import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFilterItems;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
@@ -23,9 +24,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class ItemFilter extends ItemBase { public class ItemFilter extends ItemBase {
public static final int MODE_WHITELIST = 0;
public static final int MODE_BLACKLIST = 1;
private static final String NBT_COMPARE = "Compare"; private static final String NBT_COMPARE = "Compare";
private static final String NBT_MODE = "Mode"; private static final String NBT_MODE = "Mode";
private static final String NBT_MOD_FILTER = "ModFilter"; private static final String NBT_MOD_FILTER = "ModFilter";
@@ -82,7 +80,7 @@ public class ItemFilter extends ItemBase {
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) { public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
super.addInformation(stack, world, tooltip, flag); super.addInformation(stack, world, tooltip, flag);
tooltip.add(TextFormatting.YELLOW + I18n.format("sidebutton.refinedstorage:mode." + (getMode(stack) == MODE_WHITELIST ? "whitelist" : "blacklist")) + TextFormatting.RESET); tooltip.add(TextFormatting.YELLOW + I18n.format("sidebutton.refinedstorage:mode." + (getMode(stack) == IFilter.MODE_WHITELIST ? "whitelist" : "blacklist")) + TextFormatting.RESET);
if (isModFilter(stack)) { if (isModFilter(stack)) {
tooltip.add(TextFormatting.BLUE + I18n.format("gui.refinedstorage:filter.mod_filter") + TextFormatting.RESET); tooltip.add(TextFormatting.BLUE + I18n.format("gui.refinedstorage:filter.mod_filter") + TextFormatting.RESET);
@@ -106,7 +104,7 @@ public class ItemFilter extends ItemBase {
} }
public static int getMode(ItemStack stack) { public static int getMode(ItemStack stack) {
return (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_MODE)) ? stack.getTagCompound().getInteger(NBT_MODE) : MODE_WHITELIST; return (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_MODE)) ? stack.getTagCompound().getInteger(NBT_MODE) : IFilter.MODE_WHITELIST;
} }
public static void setMode(ItemStack stack, int mode) { public static void setMode(ItemStack stack, int mode) {