This commit is contained in:
tterrag1098 committed 2015-06-12 19:06:10 -04:00
commit dedd877af7
32 files changed
+845 -11

No files matched your search

@@ -0,0 +1,20 @@
package com.jaquadro.minecraft.storagedrawers.api;
import com.jaquadro.minecraft.storagedrawers.api.pack.IPackBlockFactory;
import com.jaquadro.minecraft.storagedrawers.api.registry.IRecipeHandlerRegistry;
import com.jaquadro.minecraft.storagedrawers.api.registry.IRenderRegistry;
import com.jaquadro.minecraft.storagedrawers.api.registry.IWailaRegistry;
public interface IStorageDrawersApi
{
/**
* Recipe handlers are used to make custom recipes compatible with compacting drawers.
*/
IRecipeHandlerRegistry recipeHandlerRegistry ();
IRenderRegistry renderRegistry ();
IWailaRegistry wailaRegistry ();
IPackBlockFactory packFactory ();
}
@@ -0,0 +1,28 @@
package com.jaquadro.minecraft.storagedrawers.api;
/**
* Entry point for the public API.
*/
public class StorageDrawersApi
{
private static IStorageDrawersApi instance;
/**
* API entry point.
*
* @return The {@link IStorageDrawersApi} instance or null if the API or Storage Drawers is unavailable.
*/
public static IStorageDrawersApi instance () {
if (instance == null) {
try {
Class classApi = Class.forName( "com.jaquadro.minecraft.storagedrawers.core.Api" );
instance = (IStorageDrawersApi) classApi.getField("instance").get(null);
}
catch (Throwable t) {
return null;
}
}
return instance;
}
}
@@ -0,0 +1,19 @@
package com.jaquadro.minecraft.storagedrawers.api.event;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
import cpw.mods.fml.common.eventhandler.Event;
/**
* This event is called when a drawer has been bound to a new item. This is
* and opportunity for mods to cache extended data with the drawer.
*
* This event is also called when the drawer is changed to empty.
*/
public class DrawerPopulatedEvent extends Event
{
public final IDrawer drawer;
public DrawerPopulatedEvent (IDrawer drawer) {
this.drawer = drawer;
}
}
@@ -0,0 +1,35 @@
package com.jaquadro.minecraft.storagedrawers.api.inventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
public interface IDrawerInventory extends ISidedInventory
{
/**
* Gets a drawer's group slot index from an IInventory slot index.
*
* @param inventorySlot An IInventory slot index returned from getInventorySlot.
*/
int getDrawerSlot (int inventorySlot);
/**
* Gets an IInventory slot index suitable for operations for the given type.
*
* @param drawerSlot The index of the drawer within its group.
* @param type The type of IInventory slot to return an index for.
*/
int getInventorySlot (int drawerSlot, SlotType type);
/**
* Gets the type associated with a given IInventory slot index.
*
* @param inventorySlot An IInventory slot index returned from getInventorySlot.
*/
SlotType getInventorySlotType (int inventorySlot);
boolean canInsertItem (int slot, ItemStack stack);
boolean canExtractItem (int slot, ItemStack stack);
boolean syncInventoryIfNeeded ();
}
@@ -0,0 +1,16 @@
package com.jaquadro.minecraft.storagedrawers.api.inventory;
import net.minecraft.item.ItemStack;
public interface IInventoryAdapter
{
ItemStack getInventoryStack (SlotType slotType);
void setInStack (ItemStack stack);
void setOutStack (ItemStack stack);
void syncInventory ();
boolean syncInventoryIfNeeded ();
}
@@ -0,0 +1,15 @@
package com.jaquadro.minecraft.storagedrawers.api.inventory;
/**
* Classifies different IInventory slots according to how they should be used.
*/
public enum SlotType
{
/** An inventory slot for input-only operations; stack sizes artificially held low. */
INPUT,
/** An inventory slot for output-only operations; stack sizes artificially held high. */
OUTPUT;
public static final SlotType[] values = values();
}
@@ -0,0 +1,49 @@
package com.jaquadro.minecraft.storagedrawers.api.pack;
public enum BlockConfiguration
{
BasicFull1(BlockType.Drawers, 1, false),
BasicFull2(BlockType.Drawers, 2, false),
BasicFull4(BlockType.Drawers, 4, false),
BasicHalf2(BlockType.Drawers, 2, true),
BasicHalf4(BlockType.Drawers, 4, true),
SortingFull1(BlockType.DrawersSorting, 1, false),
SortingFull2(BlockType.DrawersSorting, 2, false),
SortingFull4(BlockType.DrawersSorting, 4, false),
SortingHalf2(BlockType.DrawersSorting, 2, true),
SortingHalf4(BlockType.DrawersSorting, 4, true),
Trim(BlockType.Trim, 0, false);
private final BlockType type;
private final int drawerCount;
private final boolean halfDepth;
BlockConfiguration (BlockType type, int count, boolean half) {
this.type = type;
this.drawerCount = count;
this.halfDepth = half;
}
public BlockType getBlockType () {
return type;
}
public int getDrawerCount () {
return drawerCount;
}
public boolean isHalfDepth () {
return halfDepth;
}
public static BlockConfiguration by (BlockType type, int drawerCount, boolean halfDepth) {
for (BlockConfiguration config : values()) {
if (config.type == type && config.drawerCount == drawerCount && config.halfDepth == halfDepth)
return config;
}
return null;
}
}
@@ -0,0 +1,8 @@
package com.jaquadro.minecraft.storagedrawers.api.pack;
public enum BlockType
{
Drawers,
DrawersSorting,
Trim
}
@@ -0,0 +1,11 @@
package com.jaquadro.minecraft.storagedrawers.api.pack;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
public interface IPackBlockFactory
{
Block createBlock (BlockConfiguration blockConfig, IPackDataResolver dataResolver);
void registerBlock (Block block, String name);
}
@@ -0,0 +1,18 @@
package com.jaquadro.minecraft.storagedrawers.api.pack;
import net.minecraft.creativetab.CreativeTabs;
public interface IPackDataResolver
{
String getPackModID ();
String getBlockName (BlockConfiguration blockConfig);
CreativeTabs getCreativeTabs (BlockType type);
boolean isValidMetaValue (int meta);
String getUnlocalizedName (int meta);
String getTexturePath (TextureType type, int meta);
}
@@ -0,0 +1,106 @@
package com.jaquadro.minecraft.storagedrawers.api.pack;
import net.minecraft.creativetab.CreativeTabs;
public class StandardDataResolver implements IPackDataResolver
{
private String modID;
private String[] unlocalizedNames;
private CreativeTabs creativeTab;
public StandardDataResolver (String modID, String[] unlocalizedNames) {
this.modID = modID;
this.unlocalizedNames = unlocalizedNames;
}
public StandardDataResolver (String modID, String[] unlocalizedNames, CreativeTabs creativeTab) {
this(modID, unlocalizedNames);
this.creativeTab = creativeTab;
}
@Override
public String getPackModID () {
return modID;
}
protected String makeBlockName (String name) {
return getPackModID().toLowerCase() + "." + name;
}
@Override
public String getBlockName (BlockConfiguration blockConfig) {
switch (blockConfig.getBlockType()) {
case Drawers:
case DrawersSorting:
if (blockConfig.getDrawerCount() == 1)
return makeBlockName("fullDrawers1");
if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth())
return makeBlockName("fullDrawers2");
if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth())
return makeBlockName("fullDrawers4");
if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth())
return makeBlockName("halfDrawers2");
if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth())
return makeBlockName("halfDrawers4");
break;
case Trim:
return makeBlockName("trim");
}
return null;
}
@Override
public CreativeTabs getCreativeTabs (BlockType type) {
return creativeTab;
}
@Override
public boolean isValidMetaValue (int meta) {
if (meta < 0 || meta >= unlocalizedNames.length)
return false;
return unlocalizedNames != null && unlocalizedNames[meta] != null;
}
@Override
public String getUnlocalizedName (int meta) {
if (!isValidMetaValue(meta))
return null;
return unlocalizedNames[meta];
}
protected String getBaseTexturePath () {
return getPackModID() + ":";
}
protected String getTextureMetaName (int meta) {
return getUnlocalizedName(meta);
}
@Override
public String getTexturePath (TextureType type, int meta) {
switch (type) {
case Front1:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_front_1";
case Front2:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_front_2";
case Front4:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_front_4";
case Side:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_side";
case SideSort:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_sort";
case SideVSplit:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_side_v";
case SideHSplit:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_side_h";
case TrimBorder:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_trim";
case TrimBlock:
return getBaseTexturePath() + "drawers_" + getTextureMetaName(meta) + "_side";
default:
return "";
}
}
}
@@ -0,0 +1,14 @@
package com.jaquadro.minecraft.storagedrawers.api.pack;
public enum TextureType
{
Front1,
Front2,
Front4,
Side,
SideSort,
SideVSplit,
SideHSplit,
TrimBorder,
TrimBlock
}
@@ -0,0 +1,19 @@
package com.jaquadro.minecraft.storagedrawers.api.registry;
import net.minecraft.item.ItemStack;
/**
* Ingredient handlers are used to get ItemStacks from ingredients in custom IRecipe implementations. If you have
* registered an IRecipeHandler that returns lists of objects that aren't ItemStacks, then you will need to
* implement an ingredient handler for those objects.
*/
public interface IIngredientHandler
{
/**
* Gets an ItemStack from an object that represents an ingredient in an IRecipe.
*
* @param object An ingredient object.
* @return An ItemStack for the given ingredient.
*/
ItemStack getItemStack (Object object);
}
@@ -0,0 +1,36 @@
package com.jaquadro.minecraft.storagedrawers.api.registry;
import net.minecraft.item.crafting.IRecipe;
import java.util.List;
/**
* Recipe handlers are used by compacting drawers to find more-compressed forms of blocks and items. If your recipe
* to craft compressed items is a custom IRecipe implementation, you will need to register a handler for it.
*/
public interface IRecipeHandler
{
/**
* Get the recipe ingredient list as an array of objects (usually used for shaped recipes).
* If your array does not contain ItemStack objects, you will need to register an {@link IIngredientHandler} to
* get an ItemStack from them.
*
* If you would prefer to return a List, return null in this method and implement {@link #getInputAsList}.
*
* @param recipe An instance of a custom {@link IRecipe}.
* @return An array of ItemStacks or objects with a registered {@link IIngredientHandler}.
*/
Object[] getInputAsArray (IRecipe recipe);
/**
* Get the recipe ingredient list as a list of objects (usually used for shapeless recipes).
* If your list does not contain ItemStack objects, you will need to register an {@link IIngredientHandler} to
* get an ItemStack from them.
*
* If you would prefer to return an array, return null in this method and implement {@link #getInputAsArray}.
*
* @param recipe An instance of a custom {@link IRecipe}.
* @return A list of ItemStacks or objects with a registered {@link IIngredientHandler}.
*/
List getInputAsList (IRecipe recipe);
}
@@ -0,0 +1,12 @@
package com.jaquadro.minecraft.storagedrawers.api.registry;
public interface IRecipeHandlerRegistry
{
void registerRecipeHandler (Class clazz, IRecipeHandler handler);
void registerIngredientHandler (Class clazz, IIngredientHandler handler);
IRecipeHandler getRecipeHandler (Class clazz);
IIngredientHandler getIngredientHandler (Class clazz);
}
@@ -0,0 +1,8 @@
package com.jaquadro.minecraft.storagedrawers.api.registry;
import com.jaquadro.minecraft.storagedrawers.api.render.IRenderLabel;
public interface IRenderRegistry
{
void registerPreLabelRenderHandler (IRenderLabel renderHandler);
}
@@ -0,0 +1,6 @@
package com.jaquadro.minecraft.storagedrawers.api.registry;
public interface IWailaRegistry
{
void registerTooltipHandler (IWailaTooltipHandler handler);
}
@@ -0,0 +1,8 @@
package com.jaquadro.minecraft.storagedrawers.api.registry;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
public interface IWailaTooltipHandler
{
String transformItemName (IDrawer drawer, String defaultName);
}
@@ -0,0 +1,9 @@
package com.jaquadro.minecraft.storagedrawers.api.render;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
import net.minecraft.tileentity.TileEntity;
public interface IRenderLabel
{
void render (TileEntity tileEntity, IDrawerGroup drawerGroup, int slot, float brightness, float partialTickTime);
}
@@ -0,0 +1,109 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public interface IDrawer
{
/**
* Gets an ItemStack of size 1 representing the type, metadata, and tags of the stored items.
* The returned ItemStack should not be modified for any reason. Make a copy if you need to store or modify it.
*/
ItemStack getStoredItemPrototype ();
/**
* Gets an ItemStack initialized to the number of items stored in this drawer.
* The returned ItemStack is guaranteed to be a new copy and can be used for any purpose. Does not affect drawer contents.
*/
ItemStack getStoredItemCopy ();
/**
* Sets the type of the stored item and initializes it to the given amount. Any existing item will be replaced.
*
* @param itemPrototype An ItemStack representing the type, metadata, and tags of the item to store.
* @param amount The amount to initialize the stored item count to.
*/
void setStoredItem (ItemStack itemPrototype, int amount);
/**
* Gets the number of items stored in this drawer.
*/
int getStoredItemCount ();
/**
* Sets the number of items stored in this drawer. Triggers syncing of inventories and client data.
* Setting a drawer's count to 0 may also result in the item type being cleared, depending in implementation.
*
* @param amount The new amount of items stored in this drawer.
*/
void setStoredItemCount (int amount);
/**
* Gets the maximum number of items that can be stored in this drawer.
* This value will vary depending on the max stack size of the stored item type.
*/
int getMaxCapacity ();
/**
* Gets the maximum number of items that could be stored in this drawer if it held the given item.
*
* @param itemPrototype The item type to query.
*/
int getMaxCapacity (ItemStack itemPrototype);
/**
* Gets the number of items that could still be added to this drawer before it is full.
*/
int getRemainingCapacity ();
/**
* Gets the max stack size of the item type stored in this drawer. Convenience method.
*/
int getStoredItemStackSize ();
/**
* Gets whether or not an item of the given type and data can be stored in this drawer.
*
* Stack size and available capacity are not considered. For drawers that are not empty, this
* method can allow ore-dictionary compatible items to be accepted into the drawer, as defined by what
* the drawer considers to be an equivalent item.
*
* @param itemPrototype An ItemStack representing the type, metadata, and tags of an item.
*/
boolean canItemBeStored (ItemStack itemPrototype);
/**
* Gets whether or not an item of the given type and data can be extracted from this drawer.
*
* This is intended to allow outbound ore-dictionary conversions of compatible items, as defined by what
* the drawer considers to be an equivalent item.
*
* @param itemPrototype An ItemStack representing the type, metadata, and tags of an item.
*/
boolean canItemBeExtracted (ItemStack itemPrototype);
/**
* Gets whether or not the drawer has items.
* A drawer set with an item type and 0 count is not considered empty.
*/
boolean isEmpty ();
/**
* Gets auxiliary data that has been associated with this drawer.
*
* @param key The key used to identify the data.
* @return An opaque object that was previously stored.
*/
Object getExtendedData (String key);
/**
* Stores auxiliary data with this drawer, mainly for use in integration.
* @param key The key to identify the data with.
* @param data The data to store.
*/
void setExtendedData (String key, Object data);
void writeToNBT (NBTTagCompound tag);
void readFromNBT (NBTTagCompound tag);
}
@@ -0,0 +1,25 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;
import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory;
public interface IDrawerGroup
{
/**
* Gets the number of drawers contained within this group.
*/
int getDrawerCount ();
/**
* Gets the drawer at the given slot within this group.
*/
IDrawer getDrawer (int slot);
/**
* Gets whether the drawer in the given slot is usable.
*/
boolean isDrawerEnabled (int slot);
IDrawerInventory getDrawerInventory ();
boolean markDirtyIfNeeded ();
}
@@ -0,0 +1,15 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public interface IDrawerGroupInteractive extends IDrawerGroup
{
ItemStack takeItemsFromSlot (int slot, int count);
int putItemsIntoSlot (int slot, ItemStack stack, int count);
int interactPutCurrentItemIntoSlot (int slot, EntityPlayer player);
int interactPutCurrentInventoryIntoSlot (int slot, EntityPlayer player);
}
@@ -0,0 +1,28 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;
/**
* Represents a drawer with items that are a fractional component of another item within the drawer group. Compacting
* Drawers are a primary example of this drawer type.
*/
public interface IFractionalDrawer extends IDrawer
{
/**
* Gets the storage ratio between the held item and the most compressed item within the drawer group.
*
* For example, most ingots have a conversion rate of 9 compared to metal blocks, and nuggets a rate of 81.
* Actual conversion rates are implementation-defined.
*/
int getConversionRate ();
/**
* Gets the number of items left in the drawer if the maximum number of equivalent compressed items had been removed.
* The equivalency is determined by the next compression tier, and not necessarily the conversion rate.
*/
int getStoredItemRemainder ();
/**
* Gets whether or not the stored item represents the smallest granularity of material that can be stored within
* the drawer group.
*/
boolean isSmallestUnit ();
}
@@ -0,0 +1,5 @@
package com.jaquadro.minecraft.storagedrawers.api.storage;
public interface INetworked
{
}
@@ -0,0 +1,21 @@
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
public interface ILockable
{
/**
* Gets whether or not a drawer or group is locked for the given lock attribute.
*/
boolean isLocked (LockAttribute attr);
/**
* Gets whether or not the lock state can be changed for the given lock attribute.
* If this method returns false, isLocked may still return true.
*/
boolean canLock (LockAttribute attr);
/**
* Sets the lock state of a drawer or group for the given lock attribute.
* If canLock returns false, this is a no-op.
*/
void setLocked (LockAttribute attr, boolean isLocked);
}
@@ -0,0 +1,16 @@
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
public interface IShroudable
{
/**
* Gets whether or not the drawer has the shrouded attribute.
* The shrouded attribute instructs the drawer to not render its item label.
*/
boolean isShrouded ();
/**
* Sets whether or not the drawer is currently shrouded.
* @return false if the operation is not supported, true otherwise.
*/
boolean setIsShrouded (boolean state);
}
@@ -0,0 +1,9 @@
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
public interface IVoidable
{
/**
* Gets whether or not the drawer has a voiding attribute.
*/
boolean isVoid ();
}
@@ -0,0 +1,37 @@
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
import java.util.EnumSet;
public enum LockAttribute
{
LOCK_POPULATED,
LOCK_EMPTY;
public int getFlagValue () {
return 1 << ordinal();
}
public static int getBitfield (EnumSet<LockAttribute> attributes) {
int value = 0;
if (attributes == null)
return value;
for (LockAttribute attr : attributes)
value |= attr.getFlagValue();
return value;
}
public static EnumSet<LockAttribute> getEnumSet (int bitfield) {
if (bitfield == 0)
return null;
EnumSet<LockAttribute> set = EnumSet.noneOf(LockAttribute.class);
for (LockAttribute attr : values()) {
if ((bitfield & attr.getFlagValue()) != 0)
set.add(attr);
}
return set;
}
}
@@ -22,24 +22,40 @@ abstract class AbstractInventory {
}
protected void updateSlot(InventoryDatabaseServer db, int slot, ItemStack stack) {
if (stack == null) {
emptySlot(db, slot);
} else {
updateSlot(db, slot, stack, stack.stackSize);
}
}
protected void updateSlot(InventoryDatabaseServer db, int slot, ItemStack stack, int count) {
SlotKey slotKey = slotKeys[slot];
ItemEntry current = slotKey != null ? slotKey.item : null;
ItemEntry key = db.lookupItem(stack, current, true);
if (key != current) {
updateSlotKey(db, slot, slotKey, key, stack);
} else if (slotKey != null && slotKey.count != stack.stackSize) {
slotKey.count = stack.stackSize;
updateSlotKey(db, slot, slotKey, key, count);
} else if (slotKey != null && slotKey.count != count) {
slotKey.count = count;
db.entryChanged(current);
}
}
private void updateSlotKey(InventoryDatabaseServer db, int slot, SlotKey slotKey, ItemEntry key, ItemStack stack) {
protected void emptySlot(InventoryDatabaseServer db, int slot) {
SlotKey slotKey = slotKeys[slot];
if (slotKey != null) {
slotKey.remove(db);
slotKeys[slot] = null;
}
}
private void updateSlotKey(InventoryDatabaseServer db, int slot, SlotKey slotKey, ItemEntry key, int count) {
if (slotKey != null) {
slotKey.remove(db);
slotKey = null;
}
if (key != null) {
slotKey = new SlotKey(this, slot, key, stack.stackSize);
slotKey = new SlotKey(this, slot, key, count);
key.addSlot(slotKey);
db.entryChanged(key);
}
@@ -0,0 +1,66 @@
package crazypants.enderio.machine.invpanel.server;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
import net.minecraft.item.ItemStack;
public class DrawerGroupInventory extends AbstractInventory {
final IDrawerGroup dg;
public DrawerGroupInventory(IDrawerGroup dg) {
this.dg = dg;
}
@Override
int scanInventory(InventoryDatabaseServer db) {
int count = dg.getDrawerCount();
if (count == 0) {
setEmpty(db);
return 0;
}
if (count != slotKeys.length) {
reset(db, count);
}
for (int i = 0; i < count; i++) {
IDrawer drawer = dg.getDrawer(i);
ItemStack stack;
int quantity;
if (drawer != null &&
(quantity = drawer.getStoredItemCount()) > 0 &&
(stack = drawer.getStoredItemPrototype()) != null &&
drawer.canItemBeExtracted(stack)) {
updateSlot(db, i, stack, quantity);
} else {
emptySlot(db, i);
}
}
return count;
}
@Override
int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int count) {
if (slot >= dg.getDrawerCount()) {
return 0;
}
IDrawer drawer = dg.getDrawer(slot);
if (drawer == null) {
return 0;
}
int remaining = drawer.getStoredItemCount();
if (remaining <= 0) {
return 0;
}
ItemStack stack = drawer.getStoredItemPrototype();
if (db.lookupItem(stack, entry, false) != entry) {
return 0;
}
if (count > remaining) {
count = remaining;
}
remaining -= count;
drawer.setStoredItemCount(remaining);
updateCount(db, slot, entry, remaining);
return count;
}
}
@@ -18,7 +18,6 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
public class InventoryDatabaseServer extends InventoryDatabase<ItemEntry> {
@@ -179,11 +178,7 @@ public class InventoryDatabaseServer extends InventoryDatabase<ItemEntry> {
this.inventories = new AbstractInventory[sources.size()];
for(int i=0; i<sources.size(); i++) {
NetworkedInventory ni = sources.get(i);
if(ni.getInventory() instanceof IDeepStorageUnit) {
inventories[i] = new DSUInventory((IDeepStorageUnit) ni.getInventory());
} else {
inventories[i] = new NormalInventory(ni);
}
inventories[i] = InventoryFactory.createInventory(ni);
}
}
@@ -0,0 +1,55 @@
package crazypants.enderio.machine.invpanel.server;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
import cpw.mods.fml.common.Loader;
import crazypants.enderio.conduit.item.NetworkedInventory;
import java.util.ArrayList;
import net.minecraft.inventory.ISidedInventory;
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
public abstract class InventoryFactory {
private static final ArrayList<InventoryFactory> factories;
static {
factories = new ArrayList<InventoryFactory>();
factories.add(new DSUFactory());
if (Loader.isModLoaded("StorageDrawers")) {
factories.add(new DrawerFactory());
}
}
static AbstractInventory createInventory(NetworkedInventory ni) {
for(InventoryFactory f : factories) {
AbstractInventory ai = f.create(ni);
if (ai != null) {
return ai;
}
}
return new NormalInventory(ni);
}
abstract AbstractInventory create(NetworkedInventory ni);
static class DSUFactory extends InventoryFactory {
@Override
AbstractInventory create(NetworkedInventory ni) {
ISidedInventory inv = ni.getInventory();
if (inv instanceof IDeepStorageUnit) {
return new DSUInventory((IDeepStorageUnit) inv);
}
return null;
}
}
static class DrawerFactory extends InventoryFactory {
@Override
AbstractInventory create(NetworkedInventory ni) {
ISidedInventory inv = ni.getInventory();
if (inv instanceof IDrawerGroup) {
return new DrawerGroupInventory((IDrawerGroup) inv);
}
return null;
}
}
}