Update Storage Drawers external storage. (#1349)

Remove embedded API and point project at new Maven repo.
This commit is contained in:
Justin Aquadro
2017-07-08 04:00:23 -04:00
committed by Raoul
parent bf1d4bb4e1
commit d6cec69b5d
5 changed files with 50 additions and 168 deletions

View File

@@ -44,6 +44,9 @@ repositories {
maven {
url "http://maven.cil.li"
}
maven {
url "https://dl.bintray.com/jaquadro/dev"
}
}
dependencies {
@@ -51,6 +54,9 @@ dependencies {
runtime "mezz.jei:jei_1.12:4.7.1.71"
deobfCompile "MCMultiPart2:MCMultiPart:2.2.2"
// deobfCompile "li.cil.oc:OpenComputers:MC1.11.2-1.7.0.28:api"
deobfCompile "com.jaquadro.minecraft.storagedrawers:StorageDrawers:1.12-5.2.2:api"
// runtime "com.jaquadro.minecraft.storagedrawers:StorageDrawers:1.12-5.2.2"
// runtime "com.jaquadro.minecraft.chameleon:Chameleon:1.12-4.1.0"
}
processResources {
@@ -70,7 +76,6 @@ processResources {
jar {
include "com/raoulvdberge/refinedstorage/**"
include "com/jaquadro/minecraft/storagedrawers/api/**"
include "assets/**"
include "mcmod.info"
include "pack.mcmeta"

View File

@@ -1,141 +0,0 @@
package com.jaquadro.minecraft.storagedrawers.api.capabilities;
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 ();
/**
* 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 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, 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
* @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, 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.
*
* The ItemStack held by itemPrototype always reports a stack size of 1.
* IT IS IMPORTANT THAT YOU NEVER MODIFY itemPrototype.
*/
class ItemRecord {
@Nonnull
public final ItemStack itemPrototype;
public final int count;
public ItemRecord(@Nonnull ItemStack itemPrototype, int count) {
this.itemPrototype = itemPrototype;
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> { }
}

View File

@@ -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,);after:storagedrawers@[1.12-5.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.2,);";
public static final String GUI_FACTORY = "com.raoulvdberge.refinedstorage.gui.config.ModGuiFactory";
public static final String UPDATE_JSON = "https://refinedstorage.raoulvdberge.com/update";

View File

@@ -1,6 +1,7 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage;
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSUtils;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
@@ -33,8 +34,8 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class NetworkNodeExternalStorage extends NetworkNode implements IStorageProvider, IGuiStorage, IComparable, IFilterable, IPrioritizable, IType, IAccessType {
@CapabilityInject(IItemRepository.class)
private static final Capability<IItemRepository> ITEM_REPOSITORY_CAPABILITY = null;
@CapabilityInject(IDrawerGroup.class)
private static final Capability<IDrawerGroup> DRAWER_GROUP_CAPABILITY = null;
public static final String ID = "external_storage";
@@ -201,11 +202,11 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP
}
if (type == IType.ITEMS) {
if (facing.hasCapability(ITEM_REPOSITORY_CAPABILITY, getDirection().getOpposite())) {
if (facing.hasCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite())) {
itemStorages.add(new StorageItemItemRepository(this, () -> {
TileEntity f = getFacingTile();
return (f != null && f.hasCapability(ITEM_REPOSITORY_CAPABILITY, getDirection().getOpposite())) ? f.getCapability(ITEM_REPOSITORY_CAPABILITY, getDirection().getOpposite()) : null;
return (f != null && f.hasCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite())) ? f.getCapability(DRAWER_GROUP_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());

View File

@@ -1,12 +1,16 @@
package com.raoulvdberge.refinedstorage.integration.storagedrawers;
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
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.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
@@ -17,17 +21,20 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
public class StorageItemItemRepository extends StorageItemExternal {
private NetworkNodeExternalStorage externalStorage;
private Supplier<IItemRepository> repositorySupplier;
@CapabilityInject(IItemRepository.class)
private static final Capability<IItemRepository> ITEM_REPOSITORY_CAPABILITY = null;
public StorageItemItemRepository(NetworkNodeExternalStorage externalStorage, Supplier<IItemRepository> repositorySupplier) {
private NetworkNodeExternalStorage externalStorage;
private Supplier<IDrawerGroup> groupSupplier;
public StorageItemItemRepository(NetworkNodeExternalStorage externalStorage, Supplier<IDrawerGroup> repositorySupplier) {
this.externalStorage = externalStorage;
this.repositorySupplier = repositorySupplier;
this.groupSupplier = repositorySupplier;
}
@Override
public Collection<ItemStack> getStacks() {
IItemRepository repository = repositorySupplier.get();
IItemRepository repository = getRepositoryFromSupplier();
if (repository == null) {
return Collections.emptyList();
@@ -39,7 +46,7 @@ public class StorageItemItemRepository extends StorageItemExternal {
@Nullable
@Override
public ItemStack insert(@Nonnull ItemStack stack, int size, boolean simulate) {
IItemRepository repository = repositorySupplier.get();
IItemRepository repository = getRepositoryFromSupplier();
if (repository == null) {
return stack;
@@ -51,24 +58,18 @@ public class StorageItemItemRepository extends StorageItemExternal {
@Nullable
@Override
public ItemStack extract(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
IItemRepository repository = repositorySupplier.get();
IItemRepository repository = getRepositoryFromSupplier();
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));
return repository.extractItem(stack, size, simulate, s -> API.instance().getComparer().isEqual(stack, s, flags));
}
@Override
public int getStored() {
IItemRepository repository = repositorySupplier.get();
IItemRepository repository = getRepositoryFromSupplier();
if (repository == null) {
return 0;
@@ -89,18 +90,34 @@ public class StorageItemItemRepository extends StorageItemExternal {
@Override
public int getCapacity() {
IItemRepository repository = repositorySupplier.get();
IDrawerGroup group = groupSupplier.get();
if (repository == null) {
if (group == null) {
return 0;
}
int capacity = 0;
long capacity = 0;
for (IItemRepository.ItemRecord record : repository.getAllItems()) {
capacity += repository.getItemCapacity(record.itemPrototype);
for (int slot : group.getAccessibleDrawerSlots()) {
IDrawer drawer = group.getDrawer(slot);
if (drawer.isEnabled()) {
capacity += drawer.getMaxCapacity();
}
}
return capacity;
if (capacity >= Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
return (int)capacity;
}
private IItemRepository getRepositoryFromSupplier() {
IDrawerGroup group = groupSupplier.get();
if (group == null) {
return null;
}
return group.getCapability(ITEM_REPOSITORY_CAPABILITY, null);
}
}