Revert "Fixes #1144 - "Refined Storage thinks that I have double of everything in my drawers when using two external storages busses""

This reverts commit 393a3ffa3c.
This commit is contained in:
raoulvdberge
2017-05-05 22:06:27 +02:00
parent 393a3ffa3c
commit 23bda54553
16 changed files with 55 additions and 89 deletions

View File

@@ -4,7 +4,6 @@
- Fixed Crafting Tweaks buttons positioned wrongly (blay09) - Fixed Crafting Tweaks buttons positioned wrongly (blay09)
- Fixed Crafting Tweaks keybindings interfering with RS keybindings (blay09) - Fixed Crafting Tweaks keybindings interfering with RS keybindings (blay09)
- Fixed crash when updating storages (raoulvdberge) - Fixed crash when updating storages (raoulvdberge)
- Fixed External Storage showing the wrong amount of items if you connect multiple External Storages to the same inventory (raoulvdberge)
### 1.4.4 ### 1.4.4
- Updated Forge to 2284 (raoulvdberge) - Updated Forge to 2284 (raoulvdberge)

View File

@@ -23,6 +23,10 @@ public interface IStorageCache<T> {
/** /**
* Adds a stack to the cache. * Adds a stack to the cache.
* <p>
* Note that this doesn't modify any of the connected storages, but just modifies the cache.
* Use {@link IStorage#insert(T, int, boolean)} to add a stack to an actual storage.
* <p>
* Will merge it with another stack if it already exists. * Will merge it with another stack if it already exists.
* *
* @param stack the stack to add, do NOT modify * @param stack the stack to add, do NOT modify
@@ -33,6 +37,9 @@ public interface IStorageCache<T> {
/** /**
* Removes a stack from the cache. * Removes a stack from the cache.
* <p>
* Note that this doesn't modify any of the connected storages, but just modifies the cache.
* Use {@link IStorage#extract(T, int, int, boolean)} to remove a stack from an actual storage.
* *
* @param stack the stack to remove, do NOT modify * @param stack the stack to remove, do NOT modify
* @param size the size to remove * @param size the size to remove
@@ -51,16 +58,7 @@ public interface IStorageCache<T> {
IStackList<T> getList(); IStackList<T> getList();
/** /**
* @return the storages in this cache, do NOT modify * @return the storages connected to this network
*/ */
List<IStorage<T>> getStorages(); List<IStorage<T>> getStorages();
/**
* Adds a storage to the cache.
* Will not add duplicate storages, it checks this with Object#equals.
*
* @param storage the storage
* @return true if the storage was added successfully, false otherwise
*/
boolean addStorage(IStorage<T> storage);
} }

View File

@@ -3,17 +3,19 @@ package com.raoulvdberge.refinedstorage.api.storage;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import java.util.List;
/** /**
* Represents a node that provides the network with storage. * Represents a node that provides the network with storage.
*/ */
public interface IStorageProvider { public interface IStorageProvider {
/** /**
* @param cache the storage cache * @param storages the item storages
*/ */
void addItemStorages(IStorageCache<ItemStack> cache); void addItemStorages(List<IStorage<ItemStack>> storages);
/** /**
* @param cache the storage cache * @param storages the fluid storages
*/ */
void addFluidStorages(IStorageCache<FluidStack> cache); void addFluidStorages(List<IStorage<FluidStack>> storages);
} }

View File

@@ -162,12 +162,8 @@ public abstract class NetworkNode implements INetworkNode, INetworkNeighborhoodA
} }
} }
public BlockPos getFacingTilePosition() {
return holder.pos().offset(holder.getDirection());
}
public TileEntity getFacingTile() { public TileEntity getFacingTile() {
return holder.world().getTileEntity(getFacingTilePosition()); return holder.world().getTileEntity(holder.pos().offset(holder.getDirection()));
} }
public IItemHandler getDrops() { public IItemHandler getDrops() {

View File

@@ -5,7 +5,7 @@ import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.RSUtils; import com.raoulvdberge.refinedstorage.RSUtils;
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster; import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.api.storage.AccessType; import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; import com.raoulvdberge.refinedstorage.api.storage.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider; import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid; import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid;
@@ -22,6 +22,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.List;
public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType { public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
public static final String ID = "fluid_storage"; public static final String ID = "fluid_storage";
@@ -117,14 +118,14 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage,
} }
@Override @Override
public void addItemStorages(IStorageCache<ItemStack> cache) { public void addItemStorages(List<IStorage<ItemStack>> storages) {
// NO OP // NO OP
} }
@Override @Override
public void addFluidStorages(IStorageCache<FluidStack> cache) { public void addFluidStorages(List<IStorage<FluidStack>> storages) {
if (storage != null) { if (storage != null) {
cache.addStorage(storage); storages.add(storage);
} }
} }

View File

@@ -5,7 +5,7 @@ import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.RSUtils; import com.raoulvdberge.refinedstorage.RSUtils;
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster; import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.api.storage.AccessType; import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; import com.raoulvdberge.refinedstorage.api.storage.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider; import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem; import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem;
@@ -22,6 +22,7 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List;
public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType { public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType {
public static final String ID = "storage"; public static final String ID = "storage";
@@ -114,14 +115,12 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto
} }
@Override @Override
public void addItemStorages(IStorageCache<ItemStack> cache) { public void addItemStorages(List<IStorage<ItemStack>> storages) {
if (storage != null) { storages.add(storage);
cache.addStorage(storage);
}
} }
@Override @Override
public void addFluidStorages(IStorageCache<FluidStack> cache) { public void addFluidStorages(List<IStorage<FluidStack>> storages) {
// NO OP // NO OP
} }

View File

@@ -21,6 +21,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IType, IExcessVoidable, IAccessType { public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IType, IExcessVoidable, IAccessType {
@@ -75,8 +76,8 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
private ItemHandlerBase itemFilters = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this)); private ItemHandlerBase itemFilters = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this));
private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this)); private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this));
private IStorageDisk<ItemStack>[] itemStorages = new IStorageDisk[8]; private IStorageDisk[] itemStorages = new IStorageDisk[8];
private IStorageDisk<FluidStack>[] fluidStorages = new IStorageDisk[8]; private IStorageDisk[] fluidStorages = new IStorageDisk[8];
private AccessType accessType = AccessType.INSERT_EXTRACT; private AccessType accessType = AccessType.INSERT_EXTRACT;
private int priority = 0; private int priority = 0;
@@ -135,19 +136,19 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS
} }
@Override @Override
public void addItemStorages(IStorageCache<ItemStack> cache) { public void addItemStorages(List<IStorage<ItemStack>> storages) {
for (IStorage<ItemStack> storage : itemStorages) { for (IStorage<ItemStack> storage : this.itemStorages) {
if (storage != null) { if (storage != null) {
cache.addStorage(storage); storages.add(storage);
} }
} }
} }
@Override @Override
public void addFluidStorages(IStorageCache<FluidStack> cache) { public void addFluidStorages(List<IStorage<FluidStack>> storages) {
for (IStorage<FluidStack> storage : fluidStorages) { for (IStorage<FluidStack> storage : this.fluidStorages) {
if (storage != null) { if (storage != null) {
cache.addStorage(storage); storages.add(storage);
} }
} }
} }

View File

@@ -6,7 +6,7 @@ import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSUtils; import com.raoulvdberge.refinedstorage.RSUtils;
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster; import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.api.storage.AccessType; import com.raoulvdberge.refinedstorage.api.storage.AccessType;
import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; import com.raoulvdberge.refinedstorage.api.storage.IStorage;
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider; import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
import com.raoulvdberge.refinedstorage.api.util.IComparer; import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiStorage; import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiStorage;
@@ -229,13 +229,13 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP
} }
@Override @Override
public void addItemStorages(IStorageCache<ItemStack> cache) { public void addItemStorages(List<IStorage<ItemStack>> storages) {
itemStorages.removeIf(storage -> !cache.addStorage(storage)); storages.addAll(this.itemStorages);
} }
@Override @Override
public void addFluidStorages(IStorageCache<FluidStack> cache) { public void addFluidStorages(List<IStorage<FluidStack>> storages) {
fluidStorages.removeIf(storage -> !cache.addStorage(storage)); storages.addAll(this.fluidStorages);
} }
@Override @Override

View File

@@ -120,9 +120,4 @@ public class StorageFluidExternal implements IStorage<FluidStack> {
public void updateCacheForcefully() { public void updateCacheForcefully() {
cache = RSUtils.copyStack(getContents()); cache = RSUtils.copyStack(getContents());
} }
@Override
public boolean equals(Object o) {
return o instanceof StorageFluidExternal && externalStorage.getFacingTilePosition().equals(((StorageFluidExternal) o).externalStorage.getFacingTilePosition());
}
} }

View File

@@ -22,13 +22,13 @@ import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class StorageItemCyclops extends StorageItemExternal { public class StorageItemCyclops extends StorageItemExternal {
private NetworkNodeExternalStorage externalStorage;
private EnumFacing opposite; private EnumFacing opposite;
private Supplier<InventoryTileEntityBase> cyclopsInv; private Supplier<InventoryTileEntityBase> cyclopsInv;
private int oldInventoryHash = -1; private int oldInventoryHash = -1;
public StorageItemCyclops(NetworkNodeExternalStorage externalStorage) { public StorageItemCyclops(NetworkNodeExternalStorage externalStorage) {
super(externalStorage); this.externalStorage = externalStorage;
this.opposite = externalStorage.getHolder().getDirection().getOpposite(); this.opposite = externalStorage.getHolder().getDirection().getOpposite();
this.cyclopsInv = () -> { this.cyclopsInv = () -> {
TileEntity f = externalStorage.getFacingTile(); TileEntity f = externalStorage.getFacingTile();
@@ -40,7 +40,6 @@ public class StorageItemCyclops extends StorageItemExternal {
@Override @Override
public void detectChanges(INetworkMaster network) { public void detectChanges(INetworkMaster network) {
InventoryTileEntityBase inv = cyclopsInv.get(); InventoryTileEntityBase inv = cyclopsInv.get();
if (inv != null) { if (inv != null) {
int inventoryHash = inv.getInventoryHash(); int inventoryHash = inv.getInventoryHash();
@@ -119,9 +118,9 @@ public class StorageItemCyclops extends StorageItemExternal {
} }
} }
public static boolean isValid(TileEntity facingTile, EnumFacing facing) { public static boolean isValid(TileEntity facingTE, EnumFacing facing) {
return facingTile instanceof InventoryTileEntityBase return facingTE instanceof InventoryTileEntityBase
&& (SlotlessItemHandlerHelper.isSlotless(facingTile, facing) && (SlotlessItemHandlerHelper.isSlotless(facingTE, facing)
|| ((InventoryTileEntityBase) facingTile).getInventory() instanceof SimpleInventory); || ((InventoryTileEntityBase) facingTE).getInventory() instanceof SimpleInventory);
} }
} }

View File

@@ -15,11 +15,11 @@ import java.util.Collections;
import java.util.function.Supplier; import java.util.function.Supplier;
public class StorageItemDrawer extends StorageItemExternal { public class StorageItemDrawer extends StorageItemExternal {
private NetworkNodeExternalStorage externalStorage;
private Supplier<IDrawer> drawerSupplier; private Supplier<IDrawer> drawerSupplier;
public StorageItemDrawer(NetworkNodeExternalStorage externalStorage, Supplier<IDrawer> drawerSupplier) { public StorageItemDrawer(NetworkNodeExternalStorage externalStorage, Supplier<IDrawer> drawerSupplier) {
super(externalStorage); this.externalStorage = externalStorage;
this.drawerSupplier = drawerSupplier; this.drawerSupplier = drawerSupplier;
} }

View File

@@ -14,11 +14,11 @@ import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
public class StorageItemDrawerGroup extends StorageItemExternal { public class StorageItemDrawerGroup extends StorageItemExternal {
private NetworkNodeExternalStorage externalStorage;
private Supplier<IDrawerGroup> groupSupplier; private Supplier<IDrawerGroup> groupSupplier;
public StorageItemDrawerGroup(NetworkNodeExternalStorage externalStorage, Supplier<IDrawerGroup> groupSupplier) { public StorageItemDrawerGroup(NetworkNodeExternalStorage externalStorage, Supplier<IDrawerGroup> groupSupplier) {
super(externalStorage); this.externalStorage = externalStorage;
this.groupSupplier = groupSupplier; this.groupSupplier = groupSupplier;
} }

View File

@@ -11,13 +11,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class StorageItemExternal implements IStorage<ItemStack> { public abstract class StorageItemExternal implements IStorage<ItemStack> {
protected NetworkNodeExternalStorage externalStorage;
private List<ItemStack> cache; private List<ItemStack> cache;
public StorageItemExternal(NetworkNodeExternalStorage externalStorage) {
this.externalStorage = externalStorage;
}
public abstract int getCapacity(); public abstract int getCapacity();
public void detectChanges(INetworkMaster network) { public void detectChanges(INetworkMaster network) {
@@ -94,9 +89,4 @@ public abstract class StorageItemExternal implements IStorage<ItemStack> {
public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) { public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) {
return remainder == null ? size : (size - remainder.getCount()); return remainder == null ? size : (size - remainder.getCount());
} }
@Override
public boolean equals(Object o) {
return o instanceof StorageItemExternal && externalStorage.getFacingTilePosition().equals(((StorageItemExternal) o).externalStorage.getFacingTilePosition());
}
} }

View File

@@ -16,12 +16,12 @@ import java.util.List;
import java.util.function.Supplier; import java.util.function.Supplier;
public class StorageItemItemHandler extends StorageItemExternal { public class StorageItemItemHandler extends StorageItemExternal {
private NetworkNodeExternalStorage externalStorage;
private Supplier<IItemHandler> handlerSupplier; private Supplier<IItemHandler> handlerSupplier;
private AccessType lockedAccessType = AccessType.INSERT_EXTRACT; private AccessType lockedAccessType = AccessType.INSERT_EXTRACT;
public StorageItemItemHandler(NetworkNodeExternalStorage externalStorage, Supplier<IItemHandler> handlerSupplier) { public StorageItemItemHandler(NetworkNodeExternalStorage externalStorage, Supplier<IItemHandler> handlerSupplier) {
super(externalStorage); this.externalStorage = externalStorage;
this.handlerSupplier = handlerSupplier; this.handlerSupplier = handlerSupplier;
if (externalStorage.getFacingTile().getBlockType().getUnlocalizedName().equals("tile.ExtraUtils2:TrashCan")) { if (externalStorage.getFacingTile().getBlockType().getUnlocalizedName().equals("tile.ExtraUtils2:TrashCan")) {

View File

@@ -27,11 +27,9 @@ public class StorageCacheFluid implements IStorageCache<FluidStack> {
public synchronized void invalidate() { public synchronized void invalidate() {
storages.clear(); storages.clear();
network.getNodeGraph() network.getNodeGraph().all().stream()
.all()
.stream()
.filter(node -> node.canUpdate() && node instanceof IStorageProvider) .filter(node -> node.canUpdate() && node instanceof IStorageProvider)
.forEach(node -> ((IStorageProvider) node).addFluidStorages(this)); .forEach(node -> ((IStorageProvider) node).addFluidStorages(storages));
list.clear(); list.clear();
@@ -80,9 +78,4 @@ public class StorageCacheFluid implements IStorageCache<FluidStack> {
public List<IStorage<FluidStack>> getStorages() { public List<IStorage<FluidStack>> getStorages() {
return storages; return storages;
} }
@Override
public boolean addStorage(IStorage<FluidStack> storage) {
return !storages.contains(storage) && storages.add(storage);
}
} }

View File

@@ -27,11 +27,9 @@ public class StorageCacheItem implements IStorageCache<ItemStack> {
public synchronized void invalidate() { public synchronized void invalidate() {
storages.clear(); storages.clear();
network.getNodeGraph() network.getNodeGraph().all().stream()
.all()
.stream()
.filter(node -> node.canUpdate() && node instanceof IStorageProvider) .filter(node -> node.canUpdate() && node instanceof IStorageProvider)
.forEach(node -> ((IStorageProvider) node).addItemStorages(this)); .forEach(node -> ((IStorageProvider) node).addItemStorages(storages));
list.clear(); list.clear();
@@ -82,9 +80,4 @@ public class StorageCacheItem implements IStorageCache<ItemStack> {
public List<IStorage<ItemStack>> getStorages() { public List<IStorage<ItemStack>> getStorages() {
return storages; return storages;
} }
@Override
public boolean addStorage(IStorage<ItemStack> storage) {
return !storages.contains(storage) && storages.add(storage);
}
} }