From 018abfccbf0ff86887f24a1ed0e2e406575e78f8 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 29 Apr 2015 01:05:47 -0400 Subject: [PATCH] Add Refined Relocation API --- .../refinedrelocation/api/APIUtils.java | 121 ++++++++++++++++ .../refinedrelocation/api/IAPIHandler.java | 33 +++++ .../refinedrelocation/api/ModObjects.java | 37 +++++ .../refinedrelocation/api/filter/IFilter.java | 8 + .../api/filter/IFilterGUI.java | 30 ++++ .../api/item/IItemRelocatorModule.java | 9 ++ .../refinedrelocation/api/package-info.java | 3 + .../api/relocator/IItemRelocator.java | 23 +++ .../api/relocator/IRelocatorModule.java | 62 ++++++++ .../api/relocator/RelocatorModuleBase.java | 137 ++++++++++++++++++ .../api/tileentity/IFilterTile.java | 8 + .../api/tileentity/IFilterTileGUI.java | 16 ++ .../api/tileentity/IGridMember.java | 16 ++ .../tileentity/IInventoryChangeListener.java | 10 ++ .../api/tileentity/ISortingInventory.java | 77 ++++++++++ .../api/tileentity/ISortingMember.java | 20 +++ .../tileentity/ISpecialSortingInventory.java | 23 +++ .../api/tileentity/grid/IGrid.java | 39 +++++ .../api/tileentity/grid/ISortingGrid.java | 31 ++++ .../api/tileentity/grid/LocalizedStack.java | 28 ++++ .../grid/SpecialLocalizedStack.java | 28 ++++ .../handlers/IGridMemberHandler.java | 43 ++++++ .../handlers/ISortingInventoryHandler.java | 17 +++ .../handlers/ISortingMemberHandler.java | 13 ++ 24 files changed, 832 insertions(+) create mode 100644 api/com/dynious/refinedrelocation/api/APIUtils.java create mode 100644 api/com/dynious/refinedrelocation/api/IAPIHandler.java create mode 100644 api/com/dynious/refinedrelocation/api/ModObjects.java create mode 100644 api/com/dynious/refinedrelocation/api/filter/IFilter.java create mode 100644 api/com/dynious/refinedrelocation/api/filter/IFilterGUI.java create mode 100644 api/com/dynious/refinedrelocation/api/item/IItemRelocatorModule.java create mode 100644 api/com/dynious/refinedrelocation/api/package-info.java create mode 100644 api/com/dynious/refinedrelocation/api/relocator/IItemRelocator.java create mode 100644 api/com/dynious/refinedrelocation/api/relocator/IRelocatorModule.java create mode 100644 api/com/dynious/refinedrelocation/api/relocator/RelocatorModuleBase.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/IFilterTile.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/IFilterTileGUI.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/IGridMember.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/IInventoryChangeListener.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/ISortingInventory.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/ISortingMember.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/ISpecialSortingInventory.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/grid/IGrid.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/grid/ISortingGrid.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/grid/LocalizedStack.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/grid/SpecialLocalizedStack.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/handlers/IGridMemberHandler.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingInventoryHandler.java create mode 100644 api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingMemberHandler.java diff --git a/api/com/dynious/refinedrelocation/api/APIUtils.java b/api/com/dynious/refinedrelocation/api/APIUtils.java new file mode 100644 index 0000000..73fc0a8 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/APIUtils.java @@ -0,0 +1,121 @@ +package com.dynious.refinedrelocation.api; + +import com.dynious.refinedrelocation.api.filter.IFilterGUI; +import com.dynious.refinedrelocation.api.relocator.IItemRelocator; +import com.dynious.refinedrelocation.api.relocator.IRelocatorModule; +import com.dynious.refinedrelocation.api.tileentity.IFilterTileGUI; +import com.dynious.refinedrelocation.api.tileentity.handlers.ISortingInventoryHandler; +import com.dynious.refinedrelocation.api.tileentity.handlers.ISortingMemberHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public final class APIUtils +{ + private static IAPIHandler apiHandler; + + static + { + try + { + Class c = Class.forName("com.dynious.refinedrelocation.APIHandler"); + apiHandler = (IAPIHandler) c.getField("instance").get(c); + } catch (Throwable e) + { + e.printStackTrace(); + } + } + + /** + * Opens the Filtering GUI for the TileEntity at the given position. + * The TileEntity should implement IFilterTileGUI. + */ + public static void openFilteringGUI(EntityPlayer entityPlayer, World world, int x, int y, int z) + { + entityPlayer.openGui(apiHandler.getModInstance(), apiHandler.getFilteringGUIID(), world, x, y, z); + } + + /** + * Creates a new instance of the standard IFilterGUI used for Sorting Chests & Filtered BlockExtenders/Buffers etc. + * If you want the IFilterGUI settings to be saved call writeToNBT(...) and readFromNBT(...). + * + * @return a new instance of the standard IFilterGUI + */ + public static IFilterGUI createStandardFilter(IFilterTileGUI filterTile) + { + return apiHandler.createStandardFilter(filterTile); + } + + /** + * Creates a new SortingMemberHandler instance. Use with ISortingMember implementers. + * + * @param owner The TileEntity this SortingMemberHandler will be used with. + * @return a new SortingMemberHandler instance. + */ + public static ISortingMemberHandler createSortingMemberHandler(TileEntity owner) + { + return apiHandler.createSortingMemberHandler(owner); + } + + /** + * Creates a new SortingInventoryHandler instance. Use with ISortingInventory implementers. + * + * @param owner The TileEntity this SortingInventoryHandler will be used with. + * @return a new SortingInventoryHandler instance. + */ + public static ISortingInventoryHandler createSortingInventoryHandler(TileEntity owner) + { + return apiHandler.createSortingInventoryHandler(owner); + } + + /** + * Registers a module for attachment to relocators. To correctly save the module your + * module MUST be registered using this. + * + * @param identifier The identifier of this module + * @param clazz The class of this module + */ + public static void registerRelocatorModule(String identifier, Class clazz) throws IllegalArgumentException + { + apiHandler.registerRelocatorModule(identifier, clazz); + } + + /** + * Will open a GUI for the module by calling the getGUI() and getContainer() methods in your module. + * + * @param relocator The identifier of this module + * @param player The Player that the GUI should open for + * @param side The side of the module that should open a GUI + */ + public static void openRelocatorModuleGUI(IItemRelocator relocator, EntityPlayer player, int side) + { + apiHandler.openRelocatorModuleGUI(relocator, player, side); + } + + /** + * Will register a class of an item that will be able to inserted into the toolbox. + * This class can also be a parent class or interface of this item. + * + * @param clazz The class, parent class or interface of the item to be added to the toolbox + */ + public static void registerToolboxClazz(Class clazz) + { + apiHandler.registerToolboxClazz(clazz); + } + + /** + * Utility method to insert items into a TileEntity (IInventory / IItemDuct etc.) + * + * @param tile TileEntity to insert into + * @param itemStack ItemStack to insert + * @param side Side to insert into + * @param simulate Simulate insertion (don't actually add it, just return when would happen) + * @return The ItemStack that was unable to be added + */ + public static ItemStack insert(TileEntity tile, ItemStack itemStack, ForgeDirection side, boolean simulate) + { + return apiHandler.insert(tile, itemStack, side, simulate); + } +} diff --git a/api/com/dynious/refinedrelocation/api/IAPIHandler.java b/api/com/dynious/refinedrelocation/api/IAPIHandler.java new file mode 100644 index 0000000..3664b91 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/IAPIHandler.java @@ -0,0 +1,33 @@ +package com.dynious.refinedrelocation.api; + +import com.dynious.refinedrelocation.api.filter.IFilterGUI; +import com.dynious.refinedrelocation.api.relocator.IItemRelocator; +import com.dynious.refinedrelocation.api.relocator.IRelocatorModule; +import com.dynious.refinedrelocation.api.tileentity.IFilterTileGUI; +import com.dynious.refinedrelocation.api.tileentity.handlers.ISortingInventoryHandler; +import com.dynious.refinedrelocation.api.tileentity.handlers.ISortingMemberHandler; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IAPIHandler +{ + public Object getModInstance(); + + public int getFilteringGUIID(); + + public IFilterGUI createStandardFilter(IFilterTileGUI filterTile); + + public ISortingMemberHandler createSortingMemberHandler(TileEntity owner); + + public ISortingInventoryHandler createSortingInventoryHandler(TileEntity owner); + + public void registerRelocatorModule(String identifier, Class clazz) throws IllegalArgumentException; + + public void openRelocatorModuleGUI(IItemRelocator relocator, EntityPlayer player, int side); + + public void registerToolboxClazz(Class clazz); + + public ItemStack insert(TileEntity tile, ItemStack itemStack, ForgeDirection side, boolean simulate); +} diff --git a/api/com/dynious/refinedrelocation/api/ModObjects.java b/api/com/dynious/refinedrelocation/api/ModObjects.java new file mode 100644 index 0000000..17e301b --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/ModObjects.java @@ -0,0 +1,37 @@ +package com.dynious.refinedrelocation.api; + +import net.minecraft.item.ItemStack; + +public class ModObjects +{ + /* Blocks */ + public static ItemStack blockExtender; + public static ItemStack advancedBlockExtender; + public static ItemStack filteredBlockExtender; + public static ItemStack advancedFilteredBlockExtender; + public static ItemStack wirelessBlockExtender; + public static ItemStack buffer; + public static ItemStack advancedBuffer; + public static ItemStack filteredBuffer; + public static ItemStack sortingChest; + public static ItemStack sortingConnector; + public static ItemStack sortingInterface; + public static ItemStack sortingImporter; + public static ItemStack filteringHopper; + public static ItemStack relocationPortal; + public static ItemStack relocationController; + public static ItemStack powerLimiter; + public static ItemStack relocator; + + /* Items */ + public static ItemStack linker; + public static ItemStack sortingUpgrade; + public static ItemStack playerRelocator; + public static ItemStack relocatorModule; + public static ItemStack toolbox; + + /* Mod Dependant Blocks (does not include metadata variants)*/ + public static ItemStack sortingIronChest; + public static ItemStack sortingBarrel; + public static ItemStack sortingAlchemicalChest; +} diff --git a/api/com/dynious/refinedrelocation/api/filter/IFilter.java b/api/com/dynious/refinedrelocation/api/filter/IFilter.java new file mode 100644 index 0000000..5cc15bf --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/filter/IFilter.java @@ -0,0 +1,8 @@ +package com.dynious.refinedrelocation.api.filter; + +import net.minecraft.item.ItemStack; + +public interface IFilter +{ + public boolean passesFilter(ItemStack itemStack); +} diff --git a/api/com/dynious/refinedrelocation/api/filter/IFilterGUI.java b/api/com/dynious/refinedrelocation/api/filter/IFilterGUI.java new file mode 100644 index 0000000..32d66df --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/filter/IFilterGUI.java @@ -0,0 +1,30 @@ +package com.dynious.refinedrelocation.api.filter; + +import net.minecraft.nbt.NBTTagCompound; + +import java.util.List; + +public interface IFilterGUI extends IFilter +{ + public int getSize(); + + public void setValue(int place, boolean value); + + public boolean getValue(int place); + + public String getName(int place); + + public boolean isBlacklisting(); + + public void setBlacklists(boolean blacklists); + + public List getWAILAInformation(NBTTagCompound compound); + + public String getUserFilter(); + + public void setUserFilter(String userFilter); + + public void writeToNBT(NBTTagCompound compound); + + public void readFromNBT(NBTTagCompound compound); +} diff --git a/api/com/dynious/refinedrelocation/api/item/IItemRelocatorModule.java b/api/com/dynious/refinedrelocation/api/item/IItemRelocatorModule.java new file mode 100644 index 0000000..99d5f03 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/item/IItemRelocatorModule.java @@ -0,0 +1,9 @@ +package com.dynious.refinedrelocation.api.item; + +import com.dynious.refinedrelocation.api.relocator.IRelocatorModule; +import net.minecraft.item.ItemStack; + +public interface IItemRelocatorModule +{ + public IRelocatorModule getRelocatorModule(ItemStack stack); +} diff --git a/api/com/dynious/refinedrelocation/api/package-info.java b/api/com/dynious/refinedrelocation/api/package-info.java new file mode 100644 index 0000000..bd551d0 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "1.0.0", owner = "RefinedRelocation", provides = "RefinedRelocationAPI") package com.dynious.refinedrelocation.api; + +import cpw.mods.fml.common.API; diff --git a/api/com/dynious/refinedrelocation/api/relocator/IItemRelocator.java b/api/com/dynious/refinedrelocation/api/relocator/IItemRelocator.java new file mode 100644 index 0000000..ea878a3 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/relocator/IItemRelocator.java @@ -0,0 +1,23 @@ +package com.dynious.refinedrelocation.api.relocator; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +public interface IItemRelocator +{ + public TileEntity getTileEntity(); + + public IRelocatorModule getRelocatorModule(int side); + + public ItemStack insert(ItemStack itemStack, int side, boolean simulate); + + public boolean getRedstoneState(); + + public TileEntity[] getConnectedInventories(); + + public IItemRelocator[] getConnectedRelocators(); + + public boolean connectsToSide(int side); + + public boolean isStuffedOnSide(int side); +} diff --git a/api/com/dynious/refinedrelocation/api/relocator/IRelocatorModule.java b/api/com/dynious/refinedrelocation/api/relocator/IRelocatorModule.java new file mode 100644 index 0000000..8141597 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/relocator/IRelocatorModule.java @@ -0,0 +1,62 @@ +package com.dynious.refinedrelocation.api.relocator; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; + +import java.util.List; + +public interface IRelocatorModule +{ + public void init(IItemRelocator relocator, int side); + + public boolean onActivated(IItemRelocator relocator, EntityPlayer player, int side, ItemStack stack); + + public void onUpdate(IItemRelocator relocator, int side); + + public ItemStack outputToSide(IItemRelocator relocator, int side, TileEntity inventory, ItemStack stack, boolean simulate); + + public boolean isItemDestination(); + + public ItemStack receiveItemStack(IItemRelocator relocator, int side, ItemStack stack, boolean input, boolean simulate); + + public void onRedstonePowerChange(boolean isPowered); + + public boolean connectsToRedstone(); + + public int strongRedstonePower(int side); + + @SideOnly(Side.CLIENT) + public GuiScreen getGUI(IItemRelocator relocator, int side, EntityPlayer player); + + public Container getContainer(IItemRelocator relocator, int side, EntityPlayer player); + + public boolean passesFilter(IItemRelocator relocator, int side, ItemStack stack, boolean input, boolean simulate); + + public void readFromNBT(IItemRelocator relocator, int side, NBTTagCompound compound); + + public void writeToNBT(IItemRelocator relocator, int side, NBTTagCompound compound); + + public void readClientData(IItemRelocator relocator, int side, NBTTagCompound compound); + + public void writeClientData(IItemRelocator relocator, int side, NBTTagCompound compound); + + public List getDrops(IItemRelocator relocator, int side); + + @SideOnly(Side.CLIENT) + public IIcon getIcon(IItemRelocator relocator, int side); + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister register); + + public String getDisplayName(); + + public List getWailaInformation(NBTTagCompound nbtData); +} diff --git a/api/com/dynious/refinedrelocation/api/relocator/RelocatorModuleBase.java b/api/com/dynious/refinedrelocation/api/relocator/RelocatorModuleBase.java new file mode 100644 index 0000000..b605d7f --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/relocator/RelocatorModuleBase.java @@ -0,0 +1,137 @@ +package com.dynious.refinedrelocation.api.relocator; + +import com.dynious.refinedrelocation.api.APIUtils; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraftforge.common.util.ForgeDirection; + +import java.util.ArrayList; +import java.util.List; + +public abstract class RelocatorModuleBase implements IRelocatorModule +{ + @Override + public void init(IItemRelocator relocator, int side) + { + } + + @Override + public boolean onActivated(IItemRelocator relocator, EntityPlayer player, int side, ItemStack stack) + { + return false; + } + + @Override + public void onUpdate(IItemRelocator relocator, int side) + { + } + + @Override + public ItemStack outputToSide(IItemRelocator relocator, int side, TileEntity inventory, ItemStack stack, boolean simulate) + { + return APIUtils.insert(inventory, stack, ForgeDirection.getOrientation(side).getOpposite(), simulate); + } + + @Override + public boolean isItemDestination() + { + return false; + } + + @Override + public ItemStack receiveItemStack(IItemRelocator relocator, int side, ItemStack stack, boolean input, boolean simulate) + { + return stack; + } + + @Override + public void onRedstonePowerChange(boolean isPowered) + { + } + + @Override + public int strongRedstonePower(int side) + { + return 0; + } + + @Override + public boolean connectsToRedstone() + { + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public GuiScreen getGUI(IItemRelocator relocator, int side, EntityPlayer player) + { + return null; + } + + @Override + public Container getContainer(IItemRelocator relocator, int side, EntityPlayer player) + { + return null; + } + + @Override + public boolean passesFilter(IItemRelocator relocator, int side, ItemStack stack, boolean input, boolean simulate) + { + return true; + } + + @Override + public void readFromNBT(IItemRelocator relocator, int side, NBTTagCompound compound) + { + } + + @Override + public void writeToNBT(IItemRelocator relocator, int side, NBTTagCompound compound) + { + } + + @Override + public void readClientData(IItemRelocator relocator, int side, NBTTagCompound compound) + { + } + + @Override + public void writeClientData(IItemRelocator relocator, int side, NBTTagCompound compound) + { + } + + @Override + public abstract List getDrops(IItemRelocator relocator, int side); + + @Override + @SideOnly(Side.CLIENT) + public abstract IIcon getIcon(IItemRelocator relocator, int side); + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister register) + { + + } + + @Override + public String getDisplayName() + { + return ""; + } + + @Override + public List getWailaInformation(NBTTagCompound nbtData) + { + List information = new ArrayList(); + return information; + } +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/IFilterTile.java b/api/com/dynious/refinedrelocation/api/tileentity/IFilterTile.java new file mode 100644 index 0000000..f2c8dce --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/IFilterTile.java @@ -0,0 +1,8 @@ +package com.dynious.refinedrelocation.api.tileentity; + +import com.dynious.refinedrelocation.api.filter.IFilter; + +public interface IFilterTile +{ + public IFilter getFilter(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/IFilterTileGUI.java b/api/com/dynious/refinedrelocation/api/tileentity/IFilterTileGUI.java new file mode 100644 index 0000000..1907460 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/IFilterTileGUI.java @@ -0,0 +1,16 @@ +package com.dynious.refinedrelocation.api.tileentity; + +import com.dynious.refinedrelocation.api.filter.IFilterGUI; +import net.minecraft.tileentity.TileEntity; + +/** + * If your TileEntity implements the interface it will be able to open the Filtering GUI. + */ +public interface IFilterTileGUI extends IFilterTile +{ + public IFilterGUI getFilter(); + + public TileEntity getTileEntity(); + + public void onFilterChanged(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/IGridMember.java b/api/com/dynious/refinedrelocation/api/tileentity/IGridMember.java new file mode 100644 index 0000000..e44a626 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/IGridMember.java @@ -0,0 +1,16 @@ +package com.dynious.refinedrelocation.api.tileentity; + +import com.dynious.refinedrelocation.api.tileentity.handlers.IGridMemberHandler; + +/** + * Base class, DO NOT USE THIS! + */ +public interface IGridMember +{ + /** + * This should return the ISortingMemberHandler of this tile. It cannot be null. + * + * @return The GridMemberHandler of this tile + */ + public IGridMemberHandler getHandler(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/IInventoryChangeListener.java b/api/com/dynious/refinedrelocation/api/tileentity/IInventoryChangeListener.java new file mode 100644 index 0000000..22d7330 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/IInventoryChangeListener.java @@ -0,0 +1,10 @@ +package com.dynious.refinedrelocation.api.tileentity; + +public interface IInventoryChangeListener +{ + /** + * This will be called when a change is made in one of the inventories in the Grid of the TileEntity + * is in. + */ + public void onInventoryChanged(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/ISortingInventory.java b/api/com/dynious/refinedrelocation/api/tileentity/ISortingInventory.java new file mode 100644 index 0000000..b0bcb5b --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/ISortingInventory.java @@ -0,0 +1,77 @@ +package com.dynious.refinedrelocation.api.tileentity; + +import com.dynious.refinedrelocation.api.tileentity.handlers.ISortingInventoryHandler; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +/** + * This extends the {@link ISortingMember} interface. + * Tile that implement this interface will be part of the Sorting Network + * and their inventory will actively be used in the network. + * The Filter set in the IFilterTile interface will be used as the filter. + *

+ * Make sure you call all required methods of {@link ISortingMember} as well as + * setInventorySlotContents(...) when this is called in your tile. + *

+ * Override markDirty() in your tile and call getHandler().onInventoryChange()! + * This will make sure the Sorting System knows there have been changes in your inventory. + * Only call + *

+ * To open the Filtering GUI for this TileEntity also implement {@link IFilterTileGUI}). + *

+ * Automatically syncs the inventory to all players in a 5 block radius. + */ +public interface ISortingInventory extends ISortingMember, IInventory, IFilterTile +{ + /** + * This should return the SortingInventoryHandler of this tile. It cannot be null. + * Create a new SortingMemberHandler instance using APIUtils.createSortingInventoryHandler(...) + * + * @return The SortingInventoryHandler of this tile + */ + public ISortingInventoryHandler getHandler(); + + /** + * Forcibly sets an ItemStack to the slotIndex + * + * @param itemStack The stack to add + * @param slotIndex The slot index to add the ItemStack in + * @return Were we able to add the ItemStack? + */ + public boolean putStackInSlot(ItemStack itemStack, int slotIndex); + + /** + * This should try to add the ItemStack to the inventory of this TileEntity + * + * @param itemStack The stack that should be put in the inventory + * @param simulate Simulate the insertion of items (only return result, no action) + * @return The remaining ItemStack after trying to put the ItemStack in the Inventory + */ + public ItemStack putInInventory(ItemStack itemStack, boolean simulate); + + /** + * The Sorting System will try to put items in the highest priority inventory. + * Blacklisting Chests have a low standard Priority, while whitelisting chests have a normal standard priority. + * Barrels have the high standard priority, because they only accept one type of item. + * This will not affect items that do not pass the Filter. + * + * @return The Priority of this ISortingInventory + */ + public Priority getPriority(); + + /** + * Sets the priority of a block to a new value. + * + * @param priority The new priority of this tile + */ + public void setPriority(Priority priority); + + enum Priority + { + HIGH, + NORMAL_HIGH, + NORMAL, + NORMAL_LOW, + LOW + } +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/ISortingMember.java b/api/com/dynious/refinedrelocation/api/tileentity/ISortingMember.java new file mode 100644 index 0000000..bbb9a85 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/ISortingMember.java @@ -0,0 +1,20 @@ +package com.dynious.refinedrelocation.api.tileentity; + + +import com.dynious.refinedrelocation.api.tileentity.handlers.ISortingMemberHandler; + +/** + * This is the interface that will make your TileEntity part of the Sorting Network. + *

+ * Make sure you call the onTileAdded() and onTileRemoved() at the right time. + */ +public interface ISortingMember extends IGridMember +{ + /** + * This should return the ISortingMemberHandler of this tile. It cannot be null. + * Create a new SortingMemberHandler instance using APIUtils.createSortingMemberHandler(...) + * + * @return The SortingMemberHandler of this tile + */ + public ISortingMemberHandler getHandler(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/ISpecialSortingInventory.java b/api/com/dynious/refinedrelocation/api/tileentity/ISpecialSortingInventory.java new file mode 100644 index 0000000..8132d3d --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/ISpecialSortingInventory.java @@ -0,0 +1,23 @@ +package com.dynious.refinedrelocation.api.tileentity; + +import com.dynious.refinedrelocation.api.tileentity.grid.SpecialLocalizedStack; + +public interface ISpecialSortingInventory extends ISortingInventory +{ + /** + * Returns a SpecialLocalizedStack for the giving slot, which will enable altering the amount of items + * in your inventory without altering the stack size of the ItemStack in the slot. + * + * @param slot The slot this stack is in. + * @return The new SpecialLocalizedStack for this slot. + */ + public SpecialLocalizedStack getLocalizedStackInSlot(int slot); + + /** + * This should alter the amount of items in your inventory in the given slot. + * + * @param slot The slot that should change size. + * @param alteration The change (positive is addition, negative is removal). + */ + public void alterStackSize(int slot, int alteration); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/grid/IGrid.java b/api/com/dynious/refinedrelocation/api/tileentity/grid/IGrid.java new file mode 100644 index 0000000..7563ec8 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/grid/IGrid.java @@ -0,0 +1,39 @@ +package com.dynious.refinedrelocation.api.tileentity.grid; + +import com.dynious.refinedrelocation.api.tileentity.handlers.IGridMemberHandler; + +import java.util.List; + +public interface IGrid +{ + /** + * Adds a member to the list of members + * + * @param member Member to be added + */ + public void addMember(IGridMemberHandler member); + + /** + * Removes a member from the list of members + * + * @param member Member to be removed + */ + public void removeMember(IGridMemberHandler member); + + /** + * Sets grid of all members to null and deletes the member list + */ + public void resetMembers(); + + /** + * Returns all members of this grid + */ + public List getMembers(); + + /** + * Merges this grid into the give grid + * + * @param grid The new Grid for this Grid should merge with + */ + public void mergeToGrid(IGrid grid); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/grid/ISortingGrid.java b/api/com/dynious/refinedrelocation/api/tileentity/grid/ISortingGrid.java new file mode 100644 index 0000000..16d7136 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/grid/ISortingGrid.java @@ -0,0 +1,31 @@ +package com.dynious.refinedrelocation.api.tileentity.grid; + + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +import java.util.List; + +public interface ISortingGrid extends IGrid +{ + /** + * Filters an ItemStack to all members of the SortingMember group + * + * @param itemStack The ItemStack to be filtered to all childs and this SortingMember + * @param simulate Simulate the insertion of items (only return result, no action) + * @return The ItemStack that was not able to fit in any ISortingInventory + */ + public ItemStack filterStackToGroup(ItemStack itemStack, TileEntity requester, int slot, boolean simulate); + + /** + * Returns a List of all ItemStacks present in the Grid + * + * @return List of all ItemStacks in the Grid + */ + public List getItemsInGrid(); + + /** + * Should be called when a change is made in one of the members on the Sorting System. + */ + public void onInventoryChange(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/grid/LocalizedStack.java b/api/com/dynious/refinedrelocation/api/tileentity/grid/LocalizedStack.java new file mode 100644 index 0000000..5eea80b --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/grid/LocalizedStack.java @@ -0,0 +1,28 @@ +package com.dynious.refinedrelocation.api.tileentity.grid; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class LocalizedStack +{ + public final ItemStack STACK; + public final IInventory INVENTORY; + public final int SLOT; + + public LocalizedStack(ItemStack stack, IInventory inventory, int slot) + { + this.STACK = stack; + this.INVENTORY = inventory; + this.SLOT = slot; + } + + public int getStackSize() + { + return STACK.stackSize; + } + + public void alterStackSize(int alteration) + { + STACK.stackSize += alteration; + } +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/grid/SpecialLocalizedStack.java b/api/com/dynious/refinedrelocation/api/tileentity/grid/SpecialLocalizedStack.java new file mode 100644 index 0000000..11d279b --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/grid/SpecialLocalizedStack.java @@ -0,0 +1,28 @@ +package com.dynious.refinedrelocation.api.tileentity.grid; + +import com.dynious.refinedrelocation.api.tileentity.ISpecialSortingInventory; +import net.minecraft.item.ItemStack; + +public class SpecialLocalizedStack extends LocalizedStack +{ + private int size; + + public SpecialLocalizedStack(ItemStack stack, ISpecialSortingInventory inventory, int slot, int size) + { + super(stack, inventory, slot); + this.size = size; + } + + @Override + public int getStackSize() + { + return size; + } + + @Override + public void alterStackSize(int alteration) + { + ((ISpecialSortingInventory) INVENTORY).alterStackSize(SLOT, alteration); + size += alteration; + } +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/handlers/IGridMemberHandler.java b/api/com/dynious/refinedrelocation/api/tileentity/handlers/IGridMemberHandler.java new file mode 100644 index 0000000..4b346fb --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/handlers/IGridMemberHandler.java @@ -0,0 +1,43 @@ +package com.dynious.refinedrelocation.api.tileentity.handlers; + +import com.dynious.refinedrelocation.api.tileentity.grid.IGrid; +import net.minecraft.tileentity.TileEntity; + +public interface IGridMemberHandler +{ + /** + * Get the owner of this Handler + * + * @return The TileEntity this Handler is linked to + */ + public TileEntity getOwner(); + + /** + * Should be called on first tick from its TileEntity + */ + public void onTileAdded(); + + /** + * Should be called by invalidate() and onChunkUnload() from its TileEntity + */ + public void onTileRemoved(); + + /** + * Get the Grid of this GridMember + * + * @return The Grid of this GridMember + */ + public IGrid getGrid(); + + /** + * Sets the Grid of a GridMember + * + * @param newLeader The new Grid for this GridMember + */ + public void setGrid(IGrid newLeader); + + /** + * @return Boolean if the GridMember can join a group + */ + public boolean canJoinGroup(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingInventoryHandler.java b/api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingInventoryHandler.java new file mode 100644 index 0000000..cfb6962 --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingInventoryHandler.java @@ -0,0 +1,17 @@ +package com.dynious.refinedrelocation.api.tileentity.handlers; + +import net.minecraft.item.ItemStack; + +public interface ISortingInventoryHandler extends ISortingMemberHandler +{ + /** + * Used when adding an item to the inventory of the TileEntity + * (Should be called by setInventorySlotContents(...) in the TileEntity class) + */ + public void setInventorySlotContents(int par1, ItemStack itemStack); + + /** + * Should be called when a change is made in one of the members on the Sorting System. + */ + public void onInventoryChange(); +} diff --git a/api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingMemberHandler.java b/api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingMemberHandler.java new file mode 100644 index 0000000..44b37ce --- /dev/null +++ b/api/com/dynious/refinedrelocation/api/tileentity/handlers/ISortingMemberHandler.java @@ -0,0 +1,13 @@ +package com.dynious.refinedrelocation.api.tileentity.handlers; + +import com.dynious.refinedrelocation.api.tileentity.grid.ISortingGrid; + +public interface ISortingMemberHandler extends IGridMemberHandler +{ + /** + * Get the SortingGrid of this GridMember + * + * @return The SortingGrid of this GridMember + */ + public ISortingGrid getGrid(); +}