Fixed usages of storage drawers API, #1346
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# Refined Storage Changelog
|
# Refined Storage Changelog
|
||||||
|
|
||||||
### 1.5.8
|
### 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 disks have to be re-inserted in the Disk Drive in order to work again after rejoining a chunk (raoulvdberge)
|
||||||
- Autocrafting can now fill water bottles with water from the fluid storage - regular bottles or pattern for regular bottles are required (raoulvdberge)
|
- Autocrafting can now fill water bottles with water from the fluid storage - regular bottles or pattern for regular bottles are required (raoulvdberge)
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
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.FluidStack;
|
||||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
@@ -31,6 +33,11 @@ import java.util.List;
|
|||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class NetworkNodeExternalStorage extends NetworkNode implements IStorageProvider, IGuiStorage, IComparable, IFilterable, IPrioritizable, IType, IAccessType {
|
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";
|
public static final String ID = "external_storage";
|
||||||
|
|
||||||
private static final String NBT_PRIORITY = "Priority";
|
private static final String NBT_PRIORITY = "Priority";
|
||||||
@@ -191,20 +198,24 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP
|
|||||||
|
|
||||||
TileEntity facing = getFacingTile();
|
TileEntity facing = getFacingTile();
|
||||||
|
|
||||||
|
if (facing == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == IType.ITEMS) {
|
if (type == IType.ITEMS) {
|
||||||
if (facing instanceof IDrawerGroup) {
|
if (facing.hasCapability(DRAWER_GROUP_CAPABILITY, getDirection().getOpposite())) {
|
||||||
itemStorages.add(new StorageItemDrawerGroup(this, () -> {
|
itemStorages.add(new StorageItemDrawerGroup(this, () -> {
|
||||||
TileEntity f = getFacingTile();
|
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, () -> {
|
itemStorages.add(new StorageItemDrawer(this, () -> {
|
||||||
TileEntity f = getFacingTile();
|
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());
|
IItemHandler itemHandler = RSUtils.getItemHandler(facing, getDirection().getOpposite());
|
||||||
|
|
||||||
if (itemHandler != null) {
|
if (itemHandler != null) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage;
|
package com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage;
|
||||||
|
|
||||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
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.api.storage.AccessType;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
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) {
|
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 != null && IFilterable.canTake(externalStorage.getItemFilters(), externalStorage.getMode(), externalStorage.getCompare(), stack) && drawer.canItemBeStored(stack)) {
|
||||||
int stored = drawer.getStoredItemCount();
|
int remainder = simulate ? Math.max(size - drawer.getAcceptingRemainingCapacity(), 0) : drawer.adjustStoredItemCount(size);
|
||||||
int remainingSpace = drawer.getMaxCapacity(stack) - stored;
|
|
||||||
|
|
||||||
int inserted = remainingSpace > size ? size : (remainingSpace <= 0) ? 0 : remainingSpace;
|
return remainder == 0 ? null : ItemHandlerHelper.copyStackWithSize(stack, remainder);
|
||||||
|
|
||||||
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 ItemHandlerHelper.copyStackWithSize(stack, size);
|
return ItemHandlerHelper.copyStackWithSize(stack, size);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
|
|||||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||||
IDrawer drawer = group.getDrawer(i);
|
IDrawer drawer = group.getDrawer(i);
|
||||||
|
|
||||||
if (group.isDrawerEnabled(i)) {
|
if (drawer.isEnabled()) {
|
||||||
stacks.add(StorageItemDrawer.getStack(drawer));
|
stacks.add(StorageItemDrawer.getStack(drawer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
|
|||||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||||
IDrawer drawer = group.getDrawer(i);
|
IDrawer drawer = group.getDrawer(i);
|
||||||
|
|
||||||
if (group.isDrawerEnabled(i)) {
|
if (drawer.isEnabled()) {
|
||||||
stored += drawer.getStoredItemCount();
|
stored += drawer.getStoredItemCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,8 +80,10 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||||
if (group.isDrawerEnabled(i)) {
|
IDrawer drawer = group.getDrawer(i);
|
||||||
capacity += group.getDrawer(i).getMaxCapacity();
|
|
||||||
|
if (drawer.isEnabled()) {
|
||||||
|
capacity += drawer.getMaxCapacity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +102,10 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||||
if (group.isDrawerEnabled(i)) {
|
IDrawer drawer = group.getDrawer(i);
|
||||||
remainder = StorageItemDrawer.insert(externalStorage, group.getDrawer(i), stack, size, simulate);
|
|
||||||
|
if (drawer.isEnabled()) {
|
||||||
|
remainder = StorageItemDrawer.insert(externalStorage, drawer, stack, size, simulate);
|
||||||
|
|
||||||
if (remainder == null || remainder.getCount() <= 0) {
|
if (remainder == null || remainder.getCount() <= 0) {
|
||||||
break;
|
break;
|
||||||
@@ -128,8 +132,10 @@ public class StorageItemDrawerGroup extends StorageItemExternal {
|
|||||||
ItemStack result = null;
|
ItemStack result = null;
|
||||||
|
|
||||||
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
for (int i = 0; i < group.getDrawerCount(); ++i) {
|
||||||
if (group.isDrawerEnabled(i)) {
|
IDrawer drawer = group.getDrawer(i);
|
||||||
ItemStack extracted = StorageItemDrawer.extract(group.getDrawer(i), stack, toExtract, flags, simulate);
|
|
||||||
|
if (drawer.isEnabled()) {
|
||||||
|
ItemStack extracted = StorageItemDrawer.extract(drawer, stack, toExtract, flags, simulate);
|
||||||
|
|
||||||
if (extracted != null) {
|
if (extracted != null) {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user