
Inventory Interface - Doesn't connect to a Inventory Connector
Shadowdane opened this issue ยท 2 comments
Minecraft Version: 1.21.1
Fabric Loader Version: 0.16.5
Fabric API Version: 0.105.0
Tom's Simple Storage Version: 2.0.9
I have one instance of the Inventory Interface block actually working in my world and it is linked with an inventory cable to an attached Inventory Connector as described in the tooltip. It shows the attached inventory on the Jade on-screen tooltip when I mouse over. I can insert items into the interface and they go into the Storage system as expected.
And below is a different Inventory Connector that is part of my main storage system and an Inventory Interface connected on the same inventory cable, but it doesn't work. Tried moving the Inventory Interface to different connection points, it only seems to work if it's directly touching the Inventory Connector block which kind of defeats the entire purpose of it. That does at least prove the interface works with that Connector, but it stops working if connected with via an Inventory cable.
My initial research, before I figured out a potential fix
I did some digging and have located a strange behavior in the code that is causing this (though I don't fully understand it yet). When the inventory interface is locating the BE to use as network access, it will pick a "random" (deterministic based on location) network node to use as the network access. The issue with this is that all inventory cable connectors return `false` for `hasConnectedInventories()` unless they have a beacon next to them, so when they are chosen (which is very common), they will invariably provide an empty inventory. This means that, in most cases, the interface cannot be used on a network that has inventory cable connectors that are used as intended, except for beacon (wireless) mechanics.This behavior can be overridden by forcing a call to setConnectorAccess
(i.e. place the interface directly next to the Inventory Connector).
@tom5454 I was able to fix this issue by changing:
diff --git a/NeoForge/src/platform-shared/java/com/tom/storagemod/block/entity/InventoryInterfaceBlockEntity.java b/NeoForge/src/platform-shared/java/com/tom/storagemod/block/entity/InventoryInterfaceBlockEntity.java
index 1391f21..8bc25c7 100644
--- a/NeoForge/src/platform-shared/java/com/tom/storagemod/block/entity/InventoryInterfaceBlockEntity.java
+++ b/NeoForge/src/platform-shared/java/com/tom/storagemod/block/entity/InventoryInterfaceBlockEntity.java
@@ -43,7 +43,7 @@ public class InventoryInterfaceBlockEntity extends PlatformBlockEntity implement
if (!level.isLoaded(p))continue;
BlockEntity be = level.getBlockEntity(p);
- if (be instanceof IInventoryConnector te) {
+ if (be instanceof IInventoryConnector te && te.hasConnectedInventories()) {
networkAccess = new WeakReference<>(te);
break;
}
This forces the interface to use a node that has connected inventories (if any), rather than just picking the first node unconditionally. I can submit a PR if you'd like but I have a strong feeling my fix is sub-optimal and that you'll probably have a better way of doing this.