Fixed usages of storage drawers API, #1346

This commit is contained in:
Raoul Van den Berge
2017-07-06 15:55:28 +02:00
parent b9df4a8c28
commit f686b3c53b
4 changed files with 33 additions and 37 deletions

View File

@@ -23,6 +23,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
@@ -31,6 +33,11 @@ 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;
public static final String ID = "external_storage";
private static final String NBT_PRIORITY = "Priority";
@@ -191,20 +198,24 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP
TileEntity facing = getFacingTile();
if (facing == null) {
return;
}
if (type == IType.ITEMS) {
if (facing instanceof IDrawerGroup) {
if (facing.hasCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite())) {
itemStorages.add(new StorageItemDrawerGroup(this, () -> {
TileEntity f = getFacingTile();
return f instanceof IDrawerGroup ? (IDrawerGroup) f : null;
return (f != null && f.hasCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite())) ? f.getCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite()) : null;
}));
} else if (facing instanceof IDrawer) {
} else if (facing.hasCapability(DRAWER_CAPABILITY, getDirection().getOpposite())) {
itemStorages.add(new StorageItemDrawer(this, () -> {
TileEntity f = getFacingTile();
return f instanceof IDrawer ? (IDrawer) f : null;
return (f != null && f.hasCapability(DRAWER_CAPABILITY, getDirection().getOpposite())) ? f.getCapability(DRAWER_CAPABILITY, getDirection().getOpposite()) : null;
}));
} else if (facing != null && !(facing.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, getDirection().getOpposite()) && facing.getCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, getDirection().getOpposite()).getNode() instanceof IStorageProvider)) {
} 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());
if (itemHandler != null) {

View File

@@ -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.attribute.IVoidable;
import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
@@ -72,30 +71,9 @@ public class StorageItemDrawer extends StorageItemExternal {
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)) {
int stored = drawer.getStoredItemCount();
int remainingSpace = drawer.getMaxCapacity(stack) - stored;
int remainder = simulate ? Math.max(size - drawer.getAcceptingRemainingCapacity(), 0) : drawer.adjustStoredItemCount(size);
int inserted = remainingSpace > size ? size : (remainingSpace <= 0) ? 0 : remainingSpace;
if (!simulate && remainingSpace > 0) {
if (drawer.isEmpty()) {
drawer.setStoredItem(stack, inserted);
} else {
drawer.setStoredItemCount(stored + inserted);
}
}
if (inserted == size) {
return null;
}
int remainder = size - inserted;
if (drawer instanceof IVoidable && ((IVoidable) drawer).isVoid()) {
return null;
}
return ItemHandlerHelper.copyStackWithSize(stack, remainder);
return remainder == 0 ? null : ItemHandlerHelper.copyStackWithSize(stack, remainder);
}
return ItemHandlerHelper.copyStackWithSize(stack, size);

View File

@@ -35,7 +35,7 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
for (int i = 0; i < group.getDrawerCount(); ++i) {
IDrawer drawer = group.getDrawer(i);
if (group.isDrawerEnabled(i)) {
if (drawer.isEnabled()) {
stacks.add(StorageItemDrawer.getStack(drawer));
}
}
@@ -56,7 +56,7 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
for (int i = 0; i < group.getDrawerCount(); ++i) {
IDrawer drawer = group.getDrawer(i);
if (group.isDrawerEnabled(i)) {
if (drawer.isEnabled()) {
stored += drawer.getStoredItemCount();
}
}
@@ -80,8 +80,10 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
}
for (int i = 0; i < group.getDrawerCount(); ++i) {
if (group.isDrawerEnabled(i)) {
capacity += group.getDrawer(i).getMaxCapacity();
IDrawer drawer = group.getDrawer(i);
if (drawer.isEnabled()) {
capacity += drawer.getMaxCapacity();
}
}
@@ -100,8 +102,10 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
}
for (int i = 0; i < group.getDrawerCount(); ++i) {
if (group.isDrawerEnabled(i)) {
remainder = StorageItemDrawer.insert(externalStorage, group.getDrawer(i), stack, size, simulate);
IDrawer drawer = group.getDrawer(i);
if (drawer.isEnabled()) {
remainder = StorageItemDrawer.insert(externalStorage, drawer, stack, size, simulate);
if (remainder == null || remainder.getCount() <= 0) {
break;
@@ -128,8 +132,10 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
ItemStack result = null;
for (int i = 0; i < group.getDrawerCount(); ++i) {
if (group.isDrawerEnabled(i)) {
ItemStack extracted = StorageItemDrawer.extract(group.getDrawer(i), stack, toExtract, flags, simulate);
IDrawer drawer = group.getDrawer(i);
if (drawer.isEnabled()) {
ItemStack extracted = StorageItemDrawer.extract(drawer, stack, toExtract, flags, simulate);
if (extracted != null) {
if (result == null) {