Fixes #1144 - "Refined Storage thinks that I have double of everything in my drawers when using two external storages busses"
This commit is contained in:
		| @@ -4,6 +4,7 @@ | ||||
| - Fixed Crafting Tweaks buttons positioned wrongly (blay09) | ||||
| - Fixed Crafting Tweaks keybindings interfering with RS keybindings (blay09) | ||||
| - 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 | ||||
| - Updated Forge to 2284 (raoulvdberge) | ||||
|   | ||||
| @@ -23,10 +23,6 @@ public interface IStorageCache<T> { | ||||
|  | ||||
|     /** | ||||
|      * 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. | ||||
|      * | ||||
|      * @param stack      the stack to add, do NOT modify | ||||
| @@ -37,9 +33,6 @@ public interface IStorageCache<T> { | ||||
|  | ||||
|     /** | ||||
|      * 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 size  the size to remove | ||||
| @@ -58,7 +51,16 @@ public interface IStorageCache<T> { | ||||
|     IStackList<T> getList(); | ||||
|  | ||||
|     /** | ||||
|      * @return the storages connected to this network | ||||
|      * @return the storages in this cache, do NOT modify | ||||
|      */ | ||||
|     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); | ||||
| } | ||||
|   | ||||
| @@ -3,19 +3,17 @@ package com.raoulvdberge.refinedstorage.api.storage; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraftforge.fluids.FluidStack; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * Represents a node that provides the network with storage. | ||||
|  */ | ||||
| public interface IStorageProvider { | ||||
|     /** | ||||
|      * @param storages the item storages | ||||
|      * @param cache the storage cache | ||||
|      */ | ||||
|     void addItemStorages(List<IStorage<ItemStack>> storages); | ||||
|     void addItemStorages(IStorageCache<ItemStack> cache); | ||||
|  | ||||
|     /** | ||||
|      * @param storages the fluid storages | ||||
|      * @param cache the storage cache | ||||
|      */ | ||||
|     void addFluidStorages(List<IStorage<FluidStack>> storages); | ||||
|     void addFluidStorages(IStorageCache<FluidStack> cache); | ||||
| } | ||||
|   | ||||
| @@ -162,8 +162,12 @@ public abstract class NetworkNode implements INetworkNode, INetworkNeighborhoodA | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public BlockPos getFacingTilePosition() { | ||||
|         return holder.pos().offset(holder.getDirection()); | ||||
|     } | ||||
|  | ||||
|     public TileEntity getFacingTile() { | ||||
|         return holder.world().getTileEntity(holder.pos().offset(holder.getDirection())); | ||||
|         return holder.world().getTileEntity(getFacingTilePosition()); | ||||
|     } | ||||
|  | ||||
|     public IItemHandler getDrops() { | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import com.raoulvdberge.refinedstorage.RSBlocks; | ||||
| import com.raoulvdberge.refinedstorage.RSUtils; | ||||
| import com.raoulvdberge.refinedstorage.api.network.INetworkMaster; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.AccessType; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorage; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider; | ||||
| import com.raoulvdberge.refinedstorage.api.util.IComparer; | ||||
| import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskFluid; | ||||
| @@ -22,7 +22,6 @@ import net.minecraftforge.fluids.FluidStack; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import javax.annotation.Nullable; | ||||
| import java.util.List; | ||||
|  | ||||
| public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType { | ||||
|     public static final String ID = "fluid_storage"; | ||||
| @@ -118,14 +117,14 @@ public class NetworkNodeFluidStorage extends NetworkNode implements IGuiStorage, | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addItemStorages(List<IStorage<ItemStack>> storages) { | ||||
|     public void addItemStorages(IStorageCache<ItemStack> cache) { | ||||
|         // NO OP | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addFluidStorages(List<IStorage<FluidStack>> storages) { | ||||
|     public void addFluidStorages(IStorageCache<FluidStack> cache) { | ||||
|         if (storage != null) { | ||||
|             storages.add(storage); | ||||
|             cache.addStorage(storage); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import com.raoulvdberge.refinedstorage.RSBlocks; | ||||
| import com.raoulvdberge.refinedstorage.RSUtils; | ||||
| import com.raoulvdberge.refinedstorage.api.network.INetworkMaster; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.AccessType; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorage; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider; | ||||
| import com.raoulvdberge.refinedstorage.api.util.IComparer; | ||||
| import com.raoulvdberge.refinedstorage.apiimpl.storage.StorageDiskItem; | ||||
| @@ -22,7 +22,6 @@ import net.minecraftforge.fluids.FluidStack; | ||||
| import net.minecraftforge.items.ItemHandlerHelper; | ||||
|  | ||||
| import javax.annotation.Nonnull; | ||||
| import java.util.List; | ||||
|  | ||||
| public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IExcessVoidable, IAccessType { | ||||
|     public static final String ID = "storage"; | ||||
| @@ -115,12 +114,14 @@ public class NetworkNodeStorage extends NetworkNode implements IGuiStorage, ISto | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addItemStorages(List<IStorage<ItemStack>> storages) { | ||||
|         storages.add(storage); | ||||
|     public void addItemStorages(IStorageCache<ItemStack> cache) { | ||||
|         if (storage != null) { | ||||
|             cache.addStorage(storage); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addFluidStorages(List<IStorage<FluidStack>> storages) { | ||||
|     public void addFluidStorages(IStorageCache<FluidStack> cache) { | ||||
|         // NO OP | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -21,7 +21,6 @@ import net.minecraftforge.fml.common.FMLCommonHandler; | ||||
| import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.items.IItemHandler; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.function.Predicate; | ||||
|  | ||||
| public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IStorageProvider, IComparable, IFilterable, IPrioritizable, IType, IExcessVoidable, IAccessType { | ||||
| @@ -76,8 +75,8 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS | ||||
|     private ItemHandlerBase itemFilters = new ItemHandlerBase(9, new ItemHandlerListenerNetworkNode(this)); | ||||
|     private ItemHandlerFluid fluidFilters = new ItemHandlerFluid(9, new ItemHandlerListenerNetworkNode(this)); | ||||
|  | ||||
|     private IStorageDisk[] itemStorages = new IStorageDisk[8]; | ||||
|     private IStorageDisk[] fluidStorages = new IStorageDisk[8]; | ||||
|     private IStorageDisk<ItemStack>[] itemStorages = new IStorageDisk[8]; | ||||
|     private IStorageDisk<FluidStack>[] fluidStorages = new IStorageDisk[8]; | ||||
|  | ||||
|     private AccessType accessType = AccessType.INSERT_EXTRACT; | ||||
|     private int priority = 0; | ||||
| @@ -136,19 +135,19 @@ public class NetworkNodeDiskDrive extends NetworkNode implements IGuiStorage, IS | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addItemStorages(List<IStorage<ItemStack>> storages) { | ||||
|         for (IStorage<ItemStack> storage : this.itemStorages) { | ||||
|     public void addItemStorages(IStorageCache<ItemStack> cache) { | ||||
|         for (IStorage<ItemStack> storage : itemStorages) { | ||||
|             if (storage != null) { | ||||
|                 storages.add(storage); | ||||
|                 cache.addStorage(storage); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addFluidStorages(List<IStorage<FluidStack>> storages) { | ||||
|         for (IStorage<FluidStack> storage : this.fluidStorages) { | ||||
|     public void addFluidStorages(IStorageCache<FluidStack> cache) { | ||||
|         for (IStorage<FluidStack> storage : fluidStorages) { | ||||
|             if (storage != null) { | ||||
|                 storages.add(storage); | ||||
|                 cache.addStorage(storage); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -6,7 +6,7 @@ import com.raoulvdberge.refinedstorage.RS; | ||||
| import com.raoulvdberge.refinedstorage.RSUtils; | ||||
| import com.raoulvdberge.refinedstorage.api.network.INetworkMaster; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.AccessType; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorage; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorageCache; | ||||
| import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider; | ||||
| import com.raoulvdberge.refinedstorage.api.util.IComparer; | ||||
| import com.raoulvdberge.refinedstorage.apiimpl.network.node.IGuiStorage; | ||||
| @@ -229,13 +229,13 @@ public class NetworkNodeExternalStorage extends NetworkNode implements IStorageP | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addItemStorages(List<IStorage<ItemStack>> storages) { | ||||
|         storages.addAll(this.itemStorages); | ||||
|     public void addItemStorages(IStorageCache<ItemStack> cache) { | ||||
|         itemStorages.removeIf(storage -> !cache.addStorage(storage)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void addFluidStorages(List<IStorage<FluidStack>> storages) { | ||||
|         storages.addAll(this.fluidStorages); | ||||
|     public void addFluidStorages(IStorageCache<FluidStack> cache) { | ||||
|         fluidStorages.removeIf(storage -> !cache.addStorage(storage)); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -120,4 +120,9 @@ public class StorageFluidExternal implements IStorage<FluidStack> { | ||||
|     public void updateCacheForcefully() { | ||||
|         cache = RSUtils.copyStack(getContents()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean equals(Object o) { | ||||
|         return o instanceof StorageFluidExternal && externalStorage.getFacingTilePosition().equals(((StorageFluidExternal) o).externalStorage.getFacingTilePosition()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -22,13 +22,13 @@ import java.util.function.Supplier; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| public class StorageItemCyclops extends StorageItemExternal { | ||||
|     private NetworkNodeExternalStorage externalStorage; | ||||
|     private EnumFacing opposite; | ||||
|     private Supplier<InventoryTileEntityBase> cyclopsInv; | ||||
|     private int oldInventoryHash = -1; | ||||
|  | ||||
|     public StorageItemCyclops(NetworkNodeExternalStorage externalStorage) { | ||||
|         this.externalStorage = externalStorage; | ||||
|         super(externalStorage); | ||||
|  | ||||
|         this.opposite = externalStorage.getHolder().getDirection().getOpposite(); | ||||
|         this.cyclopsInv = () -> { | ||||
|             TileEntity f = externalStorage.getFacingTile(); | ||||
| @@ -40,6 +40,7 @@ public class StorageItemCyclops extends StorageItemExternal { | ||||
|     @Override | ||||
|     public void detectChanges(INetworkMaster network) { | ||||
|         InventoryTileEntityBase inv = cyclopsInv.get(); | ||||
|  | ||||
|         if (inv != null) { | ||||
|             int inventoryHash = inv.getInventoryHash(); | ||||
|  | ||||
| @@ -118,9 +119,9 @@ public class StorageItemCyclops extends StorageItemExternal { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static boolean isValid(TileEntity facingTE, EnumFacing facing) { | ||||
|         return facingTE instanceof InventoryTileEntityBase | ||||
|             && (SlotlessItemHandlerHelper.isSlotless(facingTE, facing) | ||||
|             || ((InventoryTileEntityBase) facingTE).getInventory() instanceof SimpleInventory); | ||||
|     public static boolean isValid(TileEntity facingTile, EnumFacing facing) { | ||||
|         return facingTile instanceof InventoryTileEntityBase | ||||
|             && (SlotlessItemHandlerHelper.isSlotless(facingTile, facing) | ||||
|             || ((InventoryTileEntityBase) facingTile).getInventory() instanceof SimpleInventory); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -15,11 +15,11 @@ import java.util.Collections; | ||||
| import java.util.function.Supplier; | ||||
|  | ||||
| public class StorageItemDrawer extends StorageItemExternal { | ||||
|     private NetworkNodeExternalStorage externalStorage; | ||||
|     private Supplier<IDrawer> drawerSupplier; | ||||
|  | ||||
|     public StorageItemDrawer(NetworkNodeExternalStorage externalStorage, Supplier<IDrawer> drawerSupplier) { | ||||
|         this.externalStorage = externalStorage; | ||||
|         super(externalStorage); | ||||
|          | ||||
|         this.drawerSupplier = drawerSupplier; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -14,11 +14,11 @@ import java.util.List; | ||||
| import java.util.function.Supplier; | ||||
|  | ||||
| public class StorageItemDrawerGroup extends StorageItemExternal { | ||||
|     private NetworkNodeExternalStorage externalStorage; | ||||
|     private Supplier<IDrawerGroup> groupSupplier; | ||||
|  | ||||
|     public StorageItemDrawerGroup(NetworkNodeExternalStorage externalStorage, Supplier<IDrawerGroup> groupSupplier) { | ||||
|         this.externalStorage = externalStorage; | ||||
|         super(externalStorage); | ||||
|  | ||||
|         this.groupSupplier = groupSupplier; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -11,8 +11,13 @@ import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| public abstract class StorageItemExternal implements IStorage<ItemStack> { | ||||
|     protected NetworkNodeExternalStorage externalStorage; | ||||
|     private List<ItemStack> cache; | ||||
|  | ||||
|     public StorageItemExternal(NetworkNodeExternalStorage externalStorage) { | ||||
|         this.externalStorage = externalStorage; | ||||
|     } | ||||
|  | ||||
|     public abstract int getCapacity(); | ||||
|  | ||||
|     public void detectChanges(INetworkMaster network) { | ||||
| @@ -89,4 +94,9 @@ public abstract class StorageItemExternal implements IStorage<ItemStack> { | ||||
|     public int getCacheDelta(int storedPreInsertion, int size, @Nullable ItemStack remainder) { | ||||
|         return remainder == null ? size : (size - remainder.getCount()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean equals(Object o) { | ||||
|         return o instanceof StorageItemExternal && externalStorage.getFacingTilePosition().equals(((StorageItemExternal) o).externalStorage.getFacingTilePosition()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -16,12 +16,12 @@ import java.util.List; | ||||
| import java.util.function.Supplier; | ||||
|  | ||||
| public class StorageItemItemHandler extends StorageItemExternal { | ||||
|     private NetworkNodeExternalStorage externalStorage; | ||||
|     private Supplier<IItemHandler> handlerSupplier; | ||||
|     private AccessType lockedAccessType = AccessType.INSERT_EXTRACT; | ||||
|  | ||||
|     public StorageItemItemHandler(NetworkNodeExternalStorage externalStorage, Supplier<IItemHandler> handlerSupplier) { | ||||
|         this.externalStorage = externalStorage; | ||||
|         super(externalStorage); | ||||
|  | ||||
|         this.handlerSupplier = handlerSupplier; | ||||
|  | ||||
|         if (externalStorage.getFacingTile().getBlockType().getUnlocalizedName().equals("tile.ExtraUtils2:TrashCan")) { | ||||
|   | ||||
| @@ -27,9 +27,11 @@ public class StorageCacheFluid implements IStorageCache<FluidStack> { | ||||
|     public synchronized void invalidate() { | ||||
|         storages.clear(); | ||||
|  | ||||
|         network.getNodeGraph().all().stream() | ||||
|         network.getNodeGraph() | ||||
|             .all() | ||||
|             .stream() | ||||
|             .filter(node -> node.canUpdate() && node instanceof IStorageProvider) | ||||
|             .forEach(node -> ((IStorageProvider) node).addFluidStorages(storages)); | ||||
|             .forEach(node -> ((IStorageProvider) node).addFluidStorages(this)); | ||||
|  | ||||
|         list.clear(); | ||||
|  | ||||
| @@ -78,4 +80,9 @@ public class StorageCacheFluid implements IStorageCache<FluidStack> { | ||||
|     public List<IStorage<FluidStack>> getStorages() { | ||||
|         return storages; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean addStorage(IStorage<FluidStack> storage) { | ||||
|         return !storages.contains(storage) && storages.add(storage); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -27,9 +27,11 @@ public class StorageCacheItem implements IStorageCache<ItemStack> { | ||||
|     public synchronized void invalidate() { | ||||
|         storages.clear(); | ||||
|  | ||||
|         network.getNodeGraph().all().stream() | ||||
|         network.getNodeGraph() | ||||
|             .all() | ||||
|             .stream() | ||||
|             .filter(node -> node.canUpdate() && node instanceof IStorageProvider) | ||||
|             .forEach(node -> ((IStorageProvider) node).addItemStorages(storages)); | ||||
|             .forEach(node -> ((IStorageProvider) node).addItemStorages(this)); | ||||
|  | ||||
|         list.clear(); | ||||
|  | ||||
| @@ -80,4 +82,9 @@ public class StorageCacheItem implements IStorageCache<ItemStack> { | ||||
|     public List<IStorage<ItemStack>> getStorages() { | ||||
|         return storages; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public boolean addStorage(IStorage<ItemStack> storage) { | ||||
|         return !storages.contains(storage) && storages.add(storage); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 raoulvdberge
					raoulvdberge