Remove network item handlers
- If an Interface is configured to expose the entire network storage (by configuring no export slots), it will no longer expose the entire RS storage, due to performance issues - The Portable Grid no longer exposes a inventory for crossmod interaction, due to performance issues
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package com.raoulvdberge.refinedstorage.apiimpl.network.node;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.externalstorage.StorageItemItemHandler;
|
||||
import com.raoulvdberge.refinedstorage.inventory.*;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerListenerNetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerProxy;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerUpgrade;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemUpgrade;
|
||||
import com.raoulvdberge.refinedstorage.tile.config.IComparable;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
@@ -23,24 +25,10 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
||||
|
||||
private ItemHandlerBase importItems = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
|
||||
|
||||
private ItemHandlerBase exportSpecimenItems = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this)) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (network != null) {
|
||||
if (!isEmpty() && itemsStorage != null) {
|
||||
removeItemStorage(network);
|
||||
} else if (isEmpty() && itemsStorage == null) {
|
||||
createItemStorage(network);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
private ItemHandlerBase exportFilterItems = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
|
||||
private ItemHandlerBase exportItems = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
|
||||
|
||||
private IItemHandler items = new ItemHandlerProxy(importItems, exportItems);
|
||||
private ItemHandlerInterface itemsStorage;
|
||||
|
||||
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED, ItemUpgrade.TYPE_STACK, ItemUpgrade.TYPE_CRAFTING);
|
||||
|
||||
@@ -88,7 +76,7 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
ItemStack wanted = exportSpecimenItems.getStackInSlot(i);
|
||||
ItemStack wanted = exportFilterItems.getStackInSlot(i);
|
||||
ItemStack got = exportItems.getStackInSlot(i);
|
||||
|
||||
if (wanted.isEmpty()) {
|
||||
@@ -131,29 +119,6 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onConnectedStateChange(INetwork network, boolean state) {
|
||||
super.onConnectedStateChange(network, state);
|
||||
|
||||
if (state && exportSpecimenItems.isEmpty()) {
|
||||
createItemStorage(network);
|
||||
} else if (itemsStorage != null) {
|
||||
removeItemStorage(network);
|
||||
}
|
||||
}
|
||||
|
||||
private void createItemStorage(INetwork network) {
|
||||
itemsStorage = new ItemHandlerInterface(network, network.getItemStorageCache(), importItems);
|
||||
|
||||
network.getItemStorageCache().addListener(itemsStorage);
|
||||
}
|
||||
|
||||
private void removeItemStorage(INetwork network) {
|
||||
network.getItemStorageCache().removeListener(itemsStorage);
|
||||
|
||||
itemsStorage = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCompare() {
|
||||
return compare;
|
||||
@@ -195,7 +160,7 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
||||
public NBTTagCompound writeConfiguration(NBTTagCompound tag) {
|
||||
super.writeConfiguration(tag);
|
||||
|
||||
StackUtils.writeItems(exportSpecimenItems, 1, tag);
|
||||
StackUtils.writeItems(exportFilterItems, 1, tag);
|
||||
|
||||
tag.setInteger(NBT_COMPARE, compare);
|
||||
|
||||
@@ -206,7 +171,7 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
||||
public void readConfiguration(NBTTagCompound tag) {
|
||||
super.readConfiguration(tag);
|
||||
|
||||
StackUtils.readItems(exportSpecimenItems, 1, tag);
|
||||
StackUtils.readItems(exportFilterItems, 1, tag);
|
||||
|
||||
if (tag.hasKey(NBT_COMPARE)) {
|
||||
compare = tag.getInteger(NBT_COMPARE);
|
||||
@@ -217,18 +182,14 @@ public class NetworkNodeInterface extends NetworkNode implements IComparable {
|
||||
return importItems;
|
||||
}
|
||||
|
||||
public IItemHandler getExportSpecimenItems() {
|
||||
return exportSpecimenItems;
|
||||
public IItemHandler getExportFilterItems() {
|
||||
return exportFilterItems;
|
||||
}
|
||||
|
||||
public IItemHandler getExportItems() {
|
||||
return exportItems;
|
||||
}
|
||||
|
||||
public IItemHandler getItemsOrStorage() {
|
||||
return itemsStorage != null ? itemsStorage : items;
|
||||
}
|
||||
|
||||
public IItemHandler getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ContainerInterface extends ContainerBase {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new SlotFilter(tile.getNode().getExportSpecimenItems(), i, 8 + (18 * i), 54, SlotFilter.FILTER_ALLOW_SIZE));
|
||||
addSlotToContainer(new SlotFilter(tile.getNode().getExportFilterItems(), i, 8 + (18 * i), 54, SlotFilter.FILTER_ALLOW_SIZE));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.inventory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCacheListener;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ItemHandlerInterface implements IItemHandler, IStorageCacheListener<ItemStack> {
|
||||
private INetwork network;
|
||||
private IStorageCache<ItemStack> storageCache;
|
||||
private IItemHandler importItems;
|
||||
private ItemStack[] storageCacheData;
|
||||
|
||||
public ItemHandlerInterface(INetwork network, IStorageCache<ItemStack> storageCache, IItemHandler importItems) {
|
||||
this.network = network;
|
||||
this.storageCache = storageCache;
|
||||
this.importItems = importItems;
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return importItems.getSlots() + storageCacheData.length;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if (slot < importItems.getSlots()) {
|
||||
return importItems.getStackInSlot(slot);
|
||||
} else if (slot < importItems.getSlots() + storageCacheData.length) {
|
||||
return storageCacheData[slot - importItems.getSlots()];
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (slot < importItems.getSlots()) {
|
||||
return importItems.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (slot < importItems.getSlots()) {
|
||||
return ItemStack.EMPTY;
|
||||
} else if (slot < importItems.getSlots() + storageCacheData.length) {
|
||||
return StackUtils.nullToEmpty(network.extractItem(storageCacheData[slot - importItems.getSlots()], amount, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, simulate));
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return 64;
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
this.storageCacheData = storageCache.getList().getStacks().toArray(new ItemStack[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidated() {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nonnull ItemStack stack, int size) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.raoulvdberge.refinedstorage.inventory;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorage;
|
||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ItemHandlerStorage implements IItemHandler {
|
||||
private IStorage<ItemStack> storage;
|
||||
private IStorageCache<ItemStack> storageCache;
|
||||
private ItemStack[] storageCacheData;
|
||||
|
||||
public ItemHandlerStorage(IStorage<ItemStack> storage, IStorageCache<ItemStack> storageCache) {
|
||||
this.storage = storage;
|
||||
this.storageCache = storageCache;
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
// Keep 1 slot extra for new items
|
||||
return storageCacheData.length + 1;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return slot >= storageCacheData.length ? ItemStack.EMPTY : storageCacheData[slot];
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
return StackUtils.nullToEmpty(storage.insert(stack, stack.getCount(), simulate));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return slot >= storageCacheData.length ? ItemStack.EMPTY : StackUtils.nullToEmpty(storage.extract(storageCacheData[slot], amount, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT, simulate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return 64;
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
this.storageCacheData = storageCache.getList().getStacks().toArray(new ItemStack[0]);
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,7 @@ public class TileInterface extends TileNode<NetworkNodeInterface> {
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(getNode().getItemsOrStorage());
|
||||
}
|
||||
|
||||
return super.getCapability(capability, facing);
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ? CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(getNode().getItems()) : super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.raoulvdberge.refinedstorage.integration.forgeenergy.EnergyForge;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerFilter;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerListenerTile;
|
||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerStorage;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemBlockPortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemEnergyItem;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemWirelessGrid;
|
||||
@@ -50,7 +49,6 @@ import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -58,7 +56,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, IRedstoneConfigurable, IStorageCacheListener<ItemStack> {
|
||||
public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid, IRedstoneConfigurable {
|
||||
public static final TileDataParameter<Integer, TilePortableGrid> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||
public static final TileDataParameter<Integer, TilePortableGrid> ENERGY_STORED = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.energyStorage.getEnergyStored());
|
||||
public static final TileDataParameter<Integer, TilePortableGrid> SORTING_DIRECTION = new TileDataParameter<>(DataSerializers.VARINT, 0, TilePortableGrid::getSortingDirection, (t, v) -> {
|
||||
@@ -127,10 +125,6 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
||||
if (itemHandler != null) {
|
||||
cache.removeListener(TilePortableGrid.this);
|
||||
}
|
||||
|
||||
if (getStackInSlot(slot).isEmpty()) {
|
||||
storage = null;
|
||||
} else {
|
||||
@@ -146,14 +140,6 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
|
||||
cache.invalidate();
|
||||
|
||||
if (storage == null) {
|
||||
itemHandler = null;
|
||||
} else {
|
||||
itemHandler = new ItemHandlerStorage(storage, cache);
|
||||
|
||||
cache.addListener(TilePortableGrid.this);
|
||||
}
|
||||
|
||||
if (world != null) {
|
||||
checkIfDiskStateChanged();
|
||||
}
|
||||
@@ -175,7 +161,6 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
private IStorageDisk<ItemStack> storage;
|
||||
private StorageCacheItemPortable cache = new StorageCacheItemPortable(this);
|
||||
private ItemGridHandlerPortable handler = new ItemGridHandlerPortable(this, this);
|
||||
private ItemHandlerStorage itemHandler = null;
|
||||
private PortableGridDiskState diskState = PortableGridDiskState.NONE;
|
||||
private boolean connected;
|
||||
|
||||
@@ -625,19 +610,13 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityEnergy.ENERGY || (itemHandler != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) || super.hasCapability(capability, facing);
|
||||
return capability == CapabilityEnergy.ENERGY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityEnergy.ENERGY) {
|
||||
return CapabilityEnergy.ENERGY.cast(energyStorage);
|
||||
} else if (itemHandler != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemHandler);
|
||||
}
|
||||
|
||||
return super.getCapability(capability, facing);
|
||||
return capability == CapabilityEnergy.ENERGY ? CapabilityEnergy.ENERGY.cast(energyStorage) : super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
public void onOpened() {
|
||||
@@ -676,19 +655,4 @@ public class TilePortableGrid extends TileBase implements IGrid, IPortableGrid,
|
||||
return PortableGridDiskState.NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
// NO OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidated() {
|
||||
itemHandler.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nonnull ItemStack stack, int size) {
|
||||
itemHandler.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user