Update drawer API usage to only use IItemRepository (#1346), also fixes Drawer Controller priority issues (#1340)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
### 1.5.8
|
||||
- Updated Storage Drawers API (raoulvdberge)
|
||||
- Fixed bug where disks have to be re-inserted in the Disk Drive in order to work again after rejoining a chunk (raoulvdberge)
|
||||
- Fixed bug where items inserted in Storage Drawers through External Storage with a Drawer Controller wouldn't respect drawer priority rules (raoulvdberge)
|
||||
- Autocrafting can now fill water bottles with water from the fluid storage - regular bottles or pattern for regular bottles are required (raoulvdberge)
|
||||
|
||||
### 1.5.7
|
||||
|
@@ -1,10 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.registry.IRenderRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.registry.IWailaRegistry;
|
||||
|
||||
public interface IStorageDrawersApi {
|
||||
IRenderRegistry renderRegistry();
|
||||
|
||||
IWailaRegistry wailaRegistry();
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api;
|
||||
|
||||
/**
|
||||
* Entry point for the public API.
|
||||
*/
|
||||
public class StorageDrawersApi {
|
||||
private static IStorageDrawersApi instance;
|
||||
|
||||
public static final String VERSION = "2.0.0";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
@@ -4,43 +4,120 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* An interface for treating an inventory as a slotless, central repository of items.
|
||||
* <p>
|
||||
* For all operations that accept a predicate, if a predicate is supplied, a stored ItemStack must pass the predicate
|
||||
* in order to be considered for the given operation.
|
||||
* <p>
|
||||
* An IItemRepository implementation MAY relax or eliminate its own internal tests when a predicate is supplied. If
|
||||
* the predicate is derived from DefaultPredicate, then the implementation MUST apply any tests it would have applied
|
||||
* had no predicate been provided at all, in addition to testing the predicate itself.
|
||||
*/
|
||||
public interface IItemRepository {
|
||||
/**
|
||||
* Gets a list of all items in the inventory. The same item may appear multiple times with varying counts.
|
||||
*
|
||||
|
||||
* @return A list of zero or more items in the inventory.
|
||||
*/
|
||||
@Nonnull
|
||||
NonNullList<ItemRecord> getAllItems();
|
||||
NonNullList<ItemRecord> getAllItems ();
|
||||
|
||||
/**
|
||||
* Inserts an ItemStack into the inventory and returns the remainder.
|
||||
*
|
||||
* @param stack ItemStack to insert.
|
||||
* @param simulate If true, the insertion is only simulated
|
||||
* @param stack ItemStack to insert.
|
||||
* @param simulate If true, the insertion is only simulated
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The remaining ItemStack that was not inserted. If the entire stack was accepted, returns
|
||||
* ItemStack.EMPTY instead.
|
||||
*/
|
||||
@Nonnull
|
||||
ItemStack insertItem(@Nonnull ItemStack stack, boolean simulate);
|
||||
ItemStack insertItem(@Nonnull ItemStack stack, boolean simulate, Predicate<ItemStack> predicate);
|
||||
|
||||
@Nonnull
|
||||
default ItemStack insertItem(@Nonnull ItemStack stack, boolean simulate) {
|
||||
return insertItem(stack, simulate, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to extract the given ItemStack from the inventory. The returned value will be a matching ItemStack
|
||||
* with a stack size equal to or less than amount, or the empty ItemStack if the item could not be found at all.
|
||||
* The returned stack size may exceed the itemstack's getMaxStackSize() value.
|
||||
*
|
||||
* @param stack The item to extract. The stack size is ignored.
|
||||
* @param amount Amount to extract (may be greater than the stacks max limit)
|
||||
* @param simulate If true, the extraction is only simulated
|
||||
* The returned stack size may exceed the ItemStack's getMaxStackSize() value.
|
||||
|
||||
* @param stack The item to extract. The stack size is ignored.
|
||||
* @param amount Amount to extract (may be greater than the stacks max limit)
|
||||
* @param simulate If true, the extraction is only simulated
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return ItemStack extracted from the inventory, or ItemStack.EMPTY if nothing could be extracted.
|
||||
*/
|
||||
@Nonnull
|
||||
ItemStack extractItem(@Nonnull ItemStack stack, int amount, boolean simulate);
|
||||
ItemStack extractItem(@Nonnull ItemStack stack, int amount, boolean simulate, Predicate<ItemStack> predicate);
|
||||
|
||||
@Nonnull
|
||||
default ItemStack extractItem(@Nonnull ItemStack stack, int amount, boolean simulate) {
|
||||
return extractItem(stack, amount, simulate, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of items matching the given ItemStack stored by the inventory.
|
||||
*
|
||||
* @param stack ItemStack to query.
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The number of stored matching items. A value of Integer.MAX_VALUE may indicate an infinite item source.
|
||||
*/
|
||||
default int getStoredItemCount(@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
|
||||
ItemStack amount = extractItem(stack, Integer.MAX_VALUE, true, predicate);
|
||||
return amount.getCount();
|
||||
}
|
||||
|
||||
default int getStoredItemCount(@Nonnull ItemStack stack) {
|
||||
return getStoredItemCount(stack, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number items matching the given ItemStack that additionally still be stored by the inventory.
|
||||
* Remaining capacity may include space that is internally empty or unassigned to any given item.
|
||||
*
|
||||
* @param stack ItemStack to query.
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The available remaining space for matching items.
|
||||
*/
|
||||
default int getRemainingItemCapacity(@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
|
||||
stack = stack.copy();
|
||||
stack.setCount(Integer.MAX_VALUE);
|
||||
ItemStack remainder = insertItem(stack, true, predicate);
|
||||
return Integer.MAX_VALUE - remainder.getCount();
|
||||
}
|
||||
|
||||
default int getRemainingItemCapacity(@Nonnull ItemStack stack) {
|
||||
return getRemainingItemCapacity(stack, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total inventory capacity for items matching the given ItemStack.
|
||||
* Total capacity may include space that is internally empty or unassigned to any given item.
|
||||
*
|
||||
* @param stack ItemStack to query.
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The total capacity for matching items.
|
||||
*/
|
||||
default int getItemCapacity(@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
|
||||
long capacity = getStoredItemCount(stack, predicate) + getRemainingItemCapacity(stack, predicate);
|
||||
if (capacity > Integer.MAX_VALUE)
|
||||
return Integer.MAX_VALUE;
|
||||
return (int) capacity;
|
||||
}
|
||||
|
||||
default int getItemCapacity(@Nonnull ItemStack stack) {
|
||||
return getItemCapacity(stack, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* An item record representing an item and the amount stored.
|
||||
* <p>
|
||||
*
|
||||
* The ItemStack held by itemPrototype always reports a stack size of 1.
|
||||
* IT IS IMPORTANT THAT YOU NEVER MODIFY itemPrototype.
|
||||
*/
|
||||
@@ -54,4 +131,11 @@ public interface IItemRepository {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A variant of the standard Predicate interface that when passed to IItemRepository functions, will ask the
|
||||
* internal default predicate to be tested in addition to the custom predicate. An IItemRepository function
|
||||
* may choose to enforce its own predicate regardless.
|
||||
*/
|
||||
interface DefaultPredicate<T> extends Predicate<T> { }
|
||||
}
|
||||
|
@@ -1,18 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.event;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import net.minecraftforge.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;
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|event", apiVersion = StorageDrawersApi.VERSION)
|
||||
package com.jaquadro.minecraft.storagedrawers.api.event;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
|
||||
import net.minecraftforge.fml.common.API;
|
@@ -1,4 +0,0 @@
|
||||
@API(owner = "StorageDrawers", provides = "StorageDrawersAPI", apiVersion = StorageDrawersApi.VERSION)
|
||||
package com.jaquadro.minecraft.storagedrawers.api;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
@@ -1,7 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.registry;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.render.IRenderLabel;
|
||||
|
||||
public interface IRenderRegistry {
|
||||
void registerPreLabelRenderHandler(IRenderLabel renderHandler);
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.registry;
|
||||
|
||||
public interface IWailaRegistry {
|
||||
void registerTooltipHandler(IWailaTooltipHandler handler);
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.registry;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
|
||||
public interface IWailaTooltipHandler {
|
||||
String transformItemName(IDrawer drawer, String defaultName);
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|registry", apiVersion = StorageDrawersApi.VERSION)
|
||||
package com.jaquadro.minecraft.storagedrawers.api.registry;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
|
||||
import net.minecraftforge.fml.common.API;
|
@@ -1,8 +0,0 @@
|
||||
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);
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|render", apiVersion = StorageDrawersApi.VERSION)
|
||||
package com.jaquadro.minecraft.storagedrawers.api.render;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
|
||||
import net.minecraftforge.fml.common.API;
|
@@ -1,12 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.security;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
public interface ISecurityProvider {
|
||||
String getProviderID();
|
||||
|
||||
boolean hasOwnership(GameProfile profile, IProtectable target);
|
||||
|
||||
boolean hasAccess(GameProfile profile, IProtectable target);
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
public enum BlockType {
|
||||
Drawers,
|
||||
Trim
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class Drawers {
|
||||
public static final IDrawer DISABLED = new DisabledDrawer();
|
||||
public static final IFractionalDrawer DISABLED_FRACTIONAL = new DisabledFractionalDrawer();
|
||||
|
||||
private static class DisabledDrawer implements IDrawer {
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStoredItemPrototype() {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IDrawer setStoredItem(@Nonnull ItemStack itemPrototype) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredItemCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredItemCount(int amount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCapacity(@Nonnull ItemStack itemPrototype) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRemainingCapacity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canItemBeStored(@Nonnull ItemStack itemPrototype) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canItemBeExtracted(@Nonnull ItemStack itemPrototype) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DisabledFractionalDrawer extends DisabledDrawer implements IFractionalDrawer {
|
||||
@Override
|
||||
public int getConversionRate() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredItemRemainder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSmallestUnit() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
public class EmptyDrawerAttributes implements IDrawerAttributes {
|
||||
public EmptyDrawerAttributes() {
|
||||
}
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public enum EnumBasicDrawer implements IDrawerGeometry, IStringSerializable {
|
||||
FULL1(0, 1, false, "full1", "fulldrawers1"),
|
||||
FULL2(1, 2, false, "full2", "fulldrawers2"),
|
||||
FULL4(2, 4, false, "full4", "fulldrawers4"),
|
||||
HALF2(3, 2, true, "half2", "halfdrawers2"),
|
||||
HALF4(4, 4, true, "half4", "halfdrawers4");
|
||||
|
||||
private static final EnumBasicDrawer[] META_LOOKUP;
|
||||
|
||||
private final int meta;
|
||||
private final int drawerCount;
|
||||
private final boolean halfDepth;
|
||||
private final String name;
|
||||
private final String unlocalizedName;
|
||||
|
||||
EnumBasicDrawer(int meta, int drawerCount, boolean halfDepth, String name, String unlocalizedName) {
|
||||
this.meta = meta;
|
||||
this.name = name;
|
||||
this.drawerCount = drawerCount;
|
||||
this.halfDepth = halfDepth;
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
}
|
||||
|
||||
public int getMetadata() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDrawerCount() {
|
||||
return drawerCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHalfDepth() {
|
||||
return halfDepth;
|
||||
}
|
||||
|
||||
public String getUnlocalizedName() {
|
||||
return unlocalizedName;
|
||||
}
|
||||
|
||||
public static EnumBasicDrawer byMetadata(int meta) {
|
||||
if (meta < 0 || meta >= META_LOOKUP.length)
|
||||
meta = 0;
|
||||
return META_LOOKUP[meta];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
static {
|
||||
META_LOOKUP = new EnumBasicDrawer[values().length];
|
||||
for (EnumBasicDrawer upgrade : values()) {
|
||||
META_LOOKUP[upgrade.getMetadata()] = upgrade;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,145 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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.
|
||||
*/
|
||||
@Nonnull
|
||||
ItemStack getStoredItemPrototype();
|
||||
|
||||
/**
|
||||
* Sets the type of the stored item and initializes it to 0. Any existing item will be replaced.
|
||||
*
|
||||
* @param itemPrototype An ItemStack representing the type, metadata, and tags of the item to store.
|
||||
* @return The IDrawer actually set with the prototype. Some drawer groups can redirect a set operation to another member.
|
||||
*/
|
||||
@Nonnull
|
||||
IDrawer setStoredItem(@Nonnull ItemStack itemPrototype);
|
||||
|
||||
/**
|
||||
* 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 of items stored in this drawer.
|
||||
* @return The IDrawer actually set with the prototype. Some drawer groups can redirect a set operation to another member.
|
||||
*/
|
||||
@Nonnull
|
||||
default IDrawer setStoredItem(@Nonnull ItemStack itemPrototype, int amount) {
|
||||
IDrawer drawer = setStoredItem(itemPrototype);
|
||||
drawer.setStoredItemCount(amount);
|
||||
return drawer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Adds or removes a given amount from the number of items stored in this drawer.
|
||||
*
|
||||
* @param amount The amount to add (positive) or subtract (negative).
|
||||
* @return 0 if the full adjustment was committed, or a positive value representing the remainder if the full
|
||||
* amount couldn't be added or subtracted.
|
||||
*/
|
||||
default int adjustStoredItemCount(int amount) {
|
||||
if (amount > 0) {
|
||||
int insert = Math.min(amount, getRemainingCapacity());
|
||||
setStoredItemCount(getStoredItemCount() + insert);
|
||||
return amount - insert;
|
||||
} else if (amount < 0) {
|
||||
int stored = getStoredItemCount();
|
||||
int destroy = Math.min(Math.abs(amount), getStoredItemCount());
|
||||
setStoredItemCount(stored - destroy);
|
||||
return amount + destroy;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
default int getMaxCapacity() {
|
||||
return getMaxCapacity(getStoredItemPrototype());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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. Pass the empty stack to get the max capacity for an empty slot.
|
||||
*/
|
||||
int getMaxCapacity(@Nonnull ItemStack itemPrototype);
|
||||
|
||||
/**
|
||||
* Gets the number of items that could still be added to this drawer before it is full.
|
||||
*/
|
||||
int getRemainingCapacity();
|
||||
|
||||
/**
|
||||
* Gets the number of additional items that would be accepted by this drawer.
|
||||
*
|
||||
* Because a drawer may be able to handle items in excess of its full capacity, this value may be larger than
|
||||
* the result of getRemainingCapacity().
|
||||
*/
|
||||
default int getAcceptingRemainingCapacity() {
|
||||
return getRemainingCapacity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the max stack size of the item type stored in this drawer.
|
||||
*/
|
||||
default int getStoredItemStackSize() {
|
||||
@Nonnull ItemStack protoStack = getStoredItemPrototype();
|
||||
if (protoStack.isEmpty())
|
||||
return 0;
|
||||
|
||||
return protoStack.getItem().getItemStackLimit(protoStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* For drawers that are empty, locking status is considered.
|
||||
*
|
||||
* @param itemPrototype An ItemStack representing the type, metadata, and tags of an item.
|
||||
*/
|
||||
boolean canItemBeStored(@Nonnull 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(@Nonnull 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();
|
||||
|
||||
default boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,63 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute;
|
||||
|
||||
public interface IDrawerAttributes {
|
||||
/**
|
||||
* Gets whether or not the lock state can be changed for the given lock attribute.
|
||||
* If this method returns false, isItemLocked may still return true.
|
||||
*/
|
||||
default boolean canItemLock(LockAttribute attr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not a drawer or group is locked for the given lock attribute.
|
||||
*/
|
||||
default boolean isItemLocked(LockAttribute attr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the drawer has the concealed attribute.
|
||||
* The shrouded attribute instructs the drawer to not render its item label.
|
||||
*/
|
||||
default boolean isConcealed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the drawer has the sealed attribute.
|
||||
* A sealed drawer cannot be interacted with, and when broken will retain all of its items and upgrades.
|
||||
*/
|
||||
default boolean isSealed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the drawer has the quantified attribute.
|
||||
* The quantified attribute instructs the drawer to render its numerical quantity.
|
||||
*/
|
||||
default boolean isShowingQuantity() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the drawer has a voiding attribute.
|
||||
*/
|
||||
default boolean isVoid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isUnlimitedStorage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isUnlimitedVending() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isDictConvertible() {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute;
|
||||
|
||||
public interface IDrawerAttributesModifiable extends IDrawerAttributes {
|
||||
/**
|
||||
* Sets whether or not the drawer is currently concealed.
|
||||
*
|
||||
* @return false if the operation is not supported, true otherwise.
|
||||
*/
|
||||
default boolean setIsConcealed(boolean state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the lock state of a drawer or group for the given lock attribute.
|
||||
* If canItemLock returns false, this is a no-op.
|
||||
*
|
||||
* @return false if the operation is not supported, true otherwise.
|
||||
*/
|
||||
default boolean setItemLocked(LockAttribute attr, boolean isLocked) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the drawer is currently quantified.
|
||||
*
|
||||
* @return false if the operation is not supported, true otherwise.
|
||||
*/
|
||||
default boolean setIsShowingQuantity(boolean state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the drawer is currently sealed.
|
||||
*
|
||||
* @return false if the operation is not supported, true otherwise.
|
||||
*/
|
||||
default boolean setIsSealed(boolean state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean setIsVoid(boolean state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean setIsUnlimitedStorage(boolean state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean setIsUnlimitedVending(boolean state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean setIsDictConvertible(boolean state) {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
public interface IDrawerGeometry {
|
||||
boolean isHalfDepth();
|
||||
|
||||
int getDrawerCount();
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface IDrawerGroup extends ICapabilityProvider {
|
||||
/**
|
||||
* Gets the number of drawers contained within this group.
|
||||
*/
|
||||
int getDrawerCount();
|
||||
|
||||
/**
|
||||
* Gets the drawer at the given slot within this group.
|
||||
*/
|
||||
@Nonnull
|
||||
IDrawer getDrawer(int slot);
|
||||
|
||||
/**
|
||||
* Gets the list of available drawer slots in priority order.
|
||||
*/
|
||||
@Nonnull
|
||||
int[] getAccessibleDrawerSlots();
|
||||
|
||||
@Override
|
||||
default boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
default <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,27 +0,0 @@
|
||||
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();
|
||||
}
|
@@ -1,4 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
public interface INetworked {
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider;
|
||||
import net.minecraft.world.ILockableContainer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface IProtectable {
|
||||
/**
|
||||
* Gets the owner of the drawer, or null if there is no owner.
|
||||
*/
|
||||
UUID getOwner();
|
||||
|
||||
/**
|
||||
* Sets the owner of the drawer. Set to null to set no owner.
|
||||
* @return false if the operation is not supported, true otherwise.
|
||||
*/
|
||||
boolean setOwner(UUID owner);
|
||||
|
||||
/**
|
||||
* Gets the provider managing security for the target.
|
||||
* @return null to use the default provider, which enforces strict owner access.
|
||||
*/
|
||||
ISecurityProvider getSecurityProvider();
|
||||
|
||||
/**
|
||||
* Gets the lockable interface if it exists on the protected drawer.
|
||||
* @return A lockable interface, or null if lockable is not supported.
|
||||
*/
|
||||
ILockableContainer getLockableContainer();
|
||||
|
||||
/**
|
||||
* Sets the provider managing security for the target. Set to null for default provider.
|
||||
* @return false if the operation is not supported, true otherwise.
|
||||
*/
|
||||
boolean setSecurityProvider(ISecurityProvider provder);
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
|
||||
|
||||
public interface ISealable {
|
||||
/**
|
||||
* Gets whether or not the drawer has the sealed attribute.
|
||||
* A sealed drawer cannot be interacted with, and when broken will retain all of its items and upgrades.
|
||||
*/
|
||||
boolean isSealed();
|
||||
|
||||
/**
|
||||
* Sets whether or not the drawer is currently sealed.
|
||||
* @return false if the operation is not supported, true otherwise.
|
||||
*/
|
||||
boolean setIsSealed(boolean state);
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
|
||||
|
||||
@Deprecated
|
||||
public interface IVoidable {
|
||||
@Deprecated
|
||||
boolean isVoid();
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|storage-attribute", apiVersion = StorageDrawersApi.VERSION)
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage.attribute;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
|
||||
import net.minecraftforge.fml.common.API;
|
@@ -1,5 +0,0 @@
|
||||
@API(owner = "StorageDrawersAPI", provides = "StorageDrawersAPI|storage", apiVersion = StorageDrawersApi.VERSION)
|
||||
package com.jaquadro.minecraft.storagedrawers.api.storage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
|
||||
import net.minecraftforge.fml.common.API;
|
@@ -22,7 +22,7 @@ public final class RS {
|
||||
|
||||
public static final String ID = "refinedstorage";
|
||||
public static final String VERSION = "1.5.8";
|
||||
public static final String DEPENDENCIES = "required-after:forge@[14.21.0.2363,);after:mcmultipart@[2.2.1,);";
|
||||
public static final String DEPENDENCIES = "required-after:forge@[14.21.0.2363,);after:mcmultipart@[2.2.1,);after:storagedrawers@[1.12-5.2.1,);";
|
||||
public static final String GUI_FACTORY = "com.raoulvdberge.refinedstorage.gui.config.ModGuiFactory";
|
||||
public static final String UPDATE_JSON = "https://refinedstorage.raoulvdberge.com/update";
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
@@ -12,6 +11,7 @@ import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
|
||||
import com.raoulvdberge.refinedstorage.integration.storagedrawers.StorageItemItemRepository;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFluid;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerListenerNetworkNode;
|
||||
@@ -33,10 +33,8 @@ import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class NetworkNodeExternalStorage extends NetworkNode implements IStorageProvider, IGuiStorage, IComparable, IFilterable, IPrioritizable, IType, IAccessType {
|
||||
@CapabilityInject(IDrawerGroup.class)
|
||||
private static final Capability<IDrawerGroup> DRAWER_GROUP_CAPABILITY = null;
|
||||
@CapabilityInject(IDrawer.class)
|
||||
private static final Capability<IDrawer> DRAWER_CAPABILITY = null;
|
||||
@CapabilityInject(IItemRepository.class)
|
||||
private static final Capability<IItemRepository> ITEM_REPOSITORY_CAPABILITY = null;
|
||||
|
||||
public static final String ID = "external_storage";
|
||||
|
||||
@@ -203,17 +201,11 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP
|
||||
}
|
||||
|
||||
if (type == IType.ITEMS) {
|
||||
if (facing.hasCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite())) {
|
||||
itemStorages.add(new StorageItemDrawerGroup(this, () -> {
|
||||
if (facing.hasCapability(ITEM_REPOSITORY_CAPABILITY, getDirection().getOpposite())) {
|
||||
itemStorages.add(new StorageItemItemRepository(this, () -> {
|
||||
TileEntity f = getFacingTile();
|
||||
|
||||
return (f != null && f.hasCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite())) ? f.getCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite()) : null;
|
||||
}));
|
||||
} else if (facing.hasCapability(DRAWER_CAPABILITY, getDirection().getOpposite())) {
|
||||
itemStorages.add(new StorageItemDrawer(this, () -> {
|
||||
TileEntity f = getFacingTile();
|
||||
|
||||
return (f != null && f.hasCapability(DRAWER_CAPABILITY, getDirection().getOpposite())) ? f.getCapability(DRAWER_CAPABILITY, getDirection().getOpposite()) : null;
|
||||
return (f != null && f.hasCapability(ITEM_REPOSITORY_CAPABILITY, getDirection().getOpposite())) ? f.getCapability(ITEM_REPOSITORY_CAPABILITY, getDirection().getOpposite()) : null;
|
||||
}));
|
||||
} else if (!(facing.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, getDirection().getOpposite()) && facing.getCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, getDirection().getOpposite()).getNode() instanceof IStorageProvider)) {
|
||||
IItemHandler itemHandler = RSUtils.getItemHandler(facing, getDirection().getOpposite());
|
||||
|
@@ -1,109 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class StorageItemDrawer extends StorageItemExternal {
|
||||
private NetworkNodeExternalStorage externalStorage;
|
||||
private Supplier<IDrawer> drawerSupplier;
|
||||
|
||||
public StorageItemDrawer(NetworkNodeExternalStorage externalStorage, Supplier<IDrawer> drawerSupplier) {
|
||||
this.externalStorage = externalStorage;
|
||||
this.drawerSupplier = drawerSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
IDrawer drawer = drawerSupplier.get();
|
||||
|
||||
return drawer != null ? drawer.getMaxCapacity() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getStacks() {
|
||||
return Collections.singletonList(getStack(drawerSupplier.get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
return insert(externalStorage, drawerSupplier.get(), stack, size, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
return extract(drawerSupplier.get(), stack, size, flags, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
IDrawer drawer = drawerSupplier.get();
|
||||
|
||||
return drawer != null ? drawer.getStoredItemCount() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return externalStorage.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return externalStorage.getAccessType();
|
||||
}
|
||||
|
||||
public static ItemStack getStack(@Nullable IDrawer drawer) {
|
||||
if (drawer != null && !drawer.isEmpty() && drawer.getStoredItemCount() > 0) {
|
||||
return ItemHandlerHelper.copyStackWithSize(drawer.getStoredItemPrototype(), drawer.getStoredItemCount());
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static ItemStack insert(NetworkNodeExternalStorage externalStorage, @Nullable IDrawer drawer, @Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
if (drawer != null && IFilterable.canTake(externalStorage.getItemFilters(), externalStorage.getMode(), externalStorage.getCompare(), stack) && drawer.canItemBeStored(stack)) {
|
||||
if (drawer.getStoredItemCount() == 0) {
|
||||
int toInsert = size > drawer.getMaxCapacity() ? drawer.getMaxCapacity() : size;
|
||||
|
||||
if (!simulate) {
|
||||
drawer.setStoredItem(stack, toInsert);
|
||||
}
|
||||
|
||||
return toInsert == size ? null : ItemHandlerHelper.copyStackWithSize(stack, size - toInsert);
|
||||
}
|
||||
|
||||
int remainder = simulate ? Math.max(size - drawer.getAcceptingRemainingCapacity(), 0) : drawer.adjustStoredItemCount(size);
|
||||
|
||||
return remainder == 0 ? null : ItemHandlerHelper.copyStackWithSize(stack, remainder);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||
}
|
||||
|
||||
public static ItemStack extract(@Nullable IDrawer drawer, @Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
if (drawer != null && API.instance().getComparer().isEqual(stack, drawer.getStoredItemPrototype(), flags)) {
|
||||
if (size > drawer.getStoredItemCount()) {
|
||||
size = drawer.getStoredItemCount();
|
||||
}
|
||||
|
||||
ItemStack stored = drawer.getStoredItemPrototype();
|
||||
|
||||
if (!simulate) {
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() - size);
|
||||
}
|
||||
|
||||
return ItemHandlerHelper.copyStackWithSize(stored, size);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,163 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class StorageItemDrawerGroup extends StorageItemExternal {
|
||||
private NetworkNodeExternalStorage externalStorage;
|
||||
private Supplier<IDrawerGroup> groupSupplier;
|
||||
|
||||
public StorageItemDrawerGroup(NetworkNodeExternalStorage externalStorage, Supplier<IDrawerGroup> groupSupplier) {
|
||||
this.externalStorage = externalStorage;
|
||||
this.groupSupplier = groupSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getStacks() {
|
||||
IDrawerGroup group = groupSupplier.get();
|
||||
|
||||
if (group == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||
IDrawer drawer = group.getDrawer(i);
|
||||
|
||||
if (drawer.isEnabled()) {
|
||||
stacks.add(StorageItemDrawer.getStack(drawer));
|
||||
}
|
||||
}
|
||||
|
||||
return stacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
int stored = 0;
|
||||
|
||||
IDrawerGroup group = groupSupplier.get();
|
||||
|
||||
if (group == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||
IDrawer drawer = group.getDrawer(i);
|
||||
|
||||
if (drawer.isEnabled()) {
|
||||
stored += drawer.getStoredItemCount();
|
||||
}
|
||||
}
|
||||
|
||||
return stored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return externalStorage.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
int capacity = 0;
|
||||
|
||||
IDrawerGroup group = groupSupplier.get();
|
||||
|
||||
if (group == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||
IDrawer drawer = group.getDrawer(i);
|
||||
|
||||
if (drawer.isEnabled()) {
|
||||
capacity += drawer.getMaxCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
ItemStack remainder = stack;
|
||||
|
||||
IDrawerGroup group = groupSupplier.get();
|
||||
|
||||
if (group == null) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||
IDrawer drawer = group.getDrawer(i);
|
||||
|
||||
if (drawer.isEnabled()) {
|
||||
remainder = StorageItemDrawer.insert(externalStorage, drawer, stack, size, simulate);
|
||||
|
||||
if (remainder == null || remainder.getCount() <= 0) {
|
||||
break;
|
||||
} else {
|
||||
size = remainder.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainder;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
int toExtract = size;
|
||||
|
||||
IDrawerGroup group = groupSupplier.get();
|
||||
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack result = null;
|
||||
|
||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||
IDrawer drawer = group.getDrawer(i);
|
||||
|
||||
if (drawer.isEnabled()) {
|
||||
ItemStack extracted = StorageItemDrawer.extract(drawer, stack, toExtract, flags, simulate);
|
||||
|
||||
if (extracted != null) {
|
||||
if (result == null) {
|
||||
result = extracted;
|
||||
} else {
|
||||
result.grow(extracted.getCount());
|
||||
}
|
||||
|
||||
toExtract -= extracted.getCount();
|
||||
}
|
||||
|
||||
if (toExtract == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return externalStorage.getAccessType();
|
||||
}
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
package com.raoulvdberge.refinedstorage.integration.storagedrawers;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage.NetworkNodeExternalStorage;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage.StorageItemExternal;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class StorageItemItemRepository extends StorageItemExternal {
|
||||
private NetworkNodeExternalStorage externalStorage;
|
||||
private Supplier<IItemRepository> repositorySupplier;
|
||||
|
||||
public StorageItemItemRepository(NetworkNodeExternalStorage externalStorage, Supplier<IItemRepository> repositorySupplier) {
|
||||
this.externalStorage = externalStorage;
|
||||
this.repositorySupplier = repositorySupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> getStacks() {
|
||||
IItemRepository repository = repositorySupplier.get();
|
||||
|
||||
if (repository == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return repository.getAllItems().stream().map(r -> ItemHandlerHelper.copyStackWithSize(r.itemPrototype, r.count)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
|
||||
IItemRepository repository = repositorySupplier.get();
|
||||
|
||||
if (repository == null) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return RSUtils.transformEmptyToNull(repository.insertItem(ItemHandlerHelper.copyStackWithSize(stack, size), simulate));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||
IItemRepository repository = repositorySupplier.get();
|
||||
|
||||
if (repository == null) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
int toExtract = size;
|
||||
|
||||
if (toExtract > repository.getStoredItemCount(stack)) {
|
||||
toExtract = repository.getStoredItemCount(stack);
|
||||
}
|
||||
|
||||
return repository.extractItem(stack, toExtract, simulate, s -> API.instance().getComparer().isEqual(stack, s, flags));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored() {
|
||||
IItemRepository repository = repositorySupplier.get();
|
||||
|
||||
if (repository == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return repository.getAllItems().stream().mapToInt(r -> r.count).sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return externalStorage.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccessType getAccessType() {
|
||||
return externalStorage.getAccessType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
IItemRepository repository = repositorySupplier.get();
|
||||
|
||||
if (repository == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int capacity = 0;
|
||||
|
||||
for (IItemRepository.ItemRecord record : repository.getAllItems()) {
|
||||
capacity += repository.getItemCapacity(record.itemPrototype);
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user