Fixed Interface extracting from itself when trying to keep items in stock, fixes #1313
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
### 1.5.3
|
### 1.5.3
|
||||||
- Fixed Solderer crashing (raoulvdberge)
|
- Fixed Solderer crashing (raoulvdberge)
|
||||||
|
- Fixed Interface extracting from itself when trying to keep items in stock (raoulvdberge)
|
||||||
- The Portable Grid now exposes an inventory for interaction with other mods or vanilla (raoulvdberge)
|
- The Portable Grid now exposes an inventory for interaction with other mods or vanilla (raoulvdberge)
|
||||||
- The Relay now reacts instantly to a redstone signal again, removed throttling for it (raoulvdberge)
|
- The Relay now reacts instantly to a redstone signal again, removed throttling for it (raoulvdberge)
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemHandler;
|
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
import com.raoulvdberge.refinedstorage.api.network.readerwriter.IReaderWriterChannel;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.security.ISecurityManager;
|
import com.raoulvdberge.refinedstorage.api.network.security.ISecurityManager;
|
||||||
|
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
@@ -16,6 +17,7 @@ import net.minecraftforge.fluids.FluidStack;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a network, usually is a controller.
|
* Represents a network, usually is a controller.
|
||||||
@@ -200,10 +202,24 @@ public interface INetwork {
|
|||||||
* @param size the amount of that prototype that has to be extracted
|
* @param size the amount of that prototype that has to be extracted
|
||||||
* @param flags the flags to compare on, see {@link IComparer}
|
* @param flags the flags to compare on, see {@link IComparer}
|
||||||
* @param simulate true if we are simulating, false otherwise
|
* @param simulate true if we are simulating, false otherwise
|
||||||
|
* @param filter a filter for the storage
|
||||||
* @return null if we didn't extract anything, or a stack with the result
|
* @return null if we didn't extract anything, or a stack with the result
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate);
|
ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate, Predicate<IStorage> filter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts an item from this network.
|
||||||
|
*
|
||||||
|
* @param stack the prototype of the stack to extract, do NOT modify
|
||||||
|
* @param size the amount of that prototype that has to be extracted
|
||||||
|
* @param flags the flags to compare on, see {@link IComparer}
|
||||||
|
* @param simulate true if we are simulating, false otherwise
|
||||||
|
* @return null if we didn't extract anything, or a stack with the result
|
||||||
|
*/
|
||||||
|
default ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
||||||
|
return extractItem(stack, size, flags, simulate, s -> true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts an item from this network.
|
* Extracts an item from this network.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.raoulvdberge.refinedstorage.RS;
|
|||||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage.StorageItemItemHandler;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerListenerNetworkNode;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerListenerNetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerProxy;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerProxy;
|
||||||
@@ -88,7 +89,7 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
|||||||
int delta = got.isEmpty() ? wanted.getCount() : (wanted.getCount() - got.getCount());
|
int delta = got.isEmpty() ? wanted.getCount() : (wanted.getCount() - got.getCount());
|
||||||
|
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
ItemStack result = network.extractItem(wanted, delta, compare, false);
|
ItemStack result = network.extractItem(wanted, delta, compare, false, s -> !(s instanceof StorageItemItemHandler) || !((StorageItemItemHandler) s).isConnectedToInterface());
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (exportItems.getStackInSlot(i).isEmpty()) {
|
if (exportItems.getStackInSlot(i).isEmpty()) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage;
|
|||||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||||
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.TileInterface;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
import com.raoulvdberge.refinedstorage.tile.config.IFilterable;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
@@ -18,15 +19,16 @@ import java.util.function.Supplier;
|
|||||||
public class StorageItemItemHandler extends StorageItemExternal {
|
public class StorageItemItemHandler extends StorageItemExternal {
|
||||||
private NetworkNodeExternalStorage externalStorage;
|
private NetworkNodeExternalStorage externalStorage;
|
||||||
private Supplier<IItemHandler> handlerSupplier;
|
private Supplier<IItemHandler> handlerSupplier;
|
||||||
private AccessType lockedAccessType = AccessType.INSERT_EXTRACT;
|
private boolean connectedToInterface;
|
||||||
|
|
||||||
public StorageItemItemHandler(NetworkNodeExternalStorage externalStorage, Supplier<IItemHandler> handlerSupplier) {
|
public StorageItemItemHandler(NetworkNodeExternalStorage externalStorage, Supplier<IItemHandler> handlerSupplier) {
|
||||||
this.externalStorage = externalStorage;
|
this.externalStorage = externalStorage;
|
||||||
this.handlerSupplier = handlerSupplier;
|
this.handlerSupplier = handlerSupplier;
|
||||||
|
this.connectedToInterface = externalStorage.getFacingTile() instanceof TileInterface;
|
||||||
|
}
|
||||||
|
|
||||||
if (externalStorage.getFacingTile().getBlockType().getUnlocalizedName().equals("tile.ExtraUtils2:TrashCan")) {
|
public boolean isConnectedToInterface() {
|
||||||
lockedAccessType = AccessType.INSERT;
|
return connectedToInterface;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,6 +129,6 @@ public class StorageItemItemHandler extends StorageItemExternal {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccessType getAccessType() {
|
public AccessType getAccessType() {
|
||||||
return ((lockedAccessType != AccessType.INSERT_EXTRACT) ? lockedAccessType : externalStorage.getAccessType());
|
return externalStorage.getAccessType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import net.minecraftforge.items.ItemHandlerHelper;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class TileController extends TileBase implements ITickable, INetwork, IRedstoneConfigurable, INetworkNode, INetworkNodeProxy<TileController> {
|
public class TileController extends TileBase implements ITickable, INetwork, IRedstoneConfigurable, INetworkNode, INetworkNodeProxy<TileController> {
|
||||||
public static final TileDataParameter<Integer> REDSTONE_MODE = RedstoneMode.createParameter();
|
public static final TileDataParameter<Integer> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||||
@@ -453,7 +454,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate) {
|
public ItemStack extractItem(@Nonnull ItemStack stack, int size, int flags, boolean simulate, Predicate<IStorage> filter) {
|
||||||
int requested = size;
|
int requested = size;
|
||||||
int received = 0;
|
int received = 0;
|
||||||
|
|
||||||
@@ -464,7 +465,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
|||||||
for (IStorage<ItemStack> storage : this.itemStorage.getStorages()) {
|
for (IStorage<ItemStack> storage : this.itemStorage.getStorages()) {
|
||||||
ItemStack took = null;
|
ItemStack took = null;
|
||||||
|
|
||||||
if (storage.getAccessType() != AccessType.INSERT) {
|
if (filter.test(storage) && storage.getAccessType() != AccessType.INSERT) {
|
||||||
took = storage.extract(stack, requested - received, flags, simulate);
|
took = storage.extract(stack, requested - received, flags, simulate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user