Tech Reborn

Tech Reborn

30M Downloads

Storage Unit/Buffer doesn't work with CC: Tweaked's peripheral system

Bamberghh opened this issue ยท 4 comments

commented

Describe the bug
The CC: Tweaked mod has a peripheral system, one of many things it allows is to interface with blocks with an inventory and pull/push items from/into them. This functionality is generic and should work with any blocks, modded or not.

The bug is that this doesn't work with Tech Reborn's storage units/buffers, while it does work with any other TR machine, like Tank Unit, Auto Crafting Table, Grinder, etc. The computers/wired modems for some reason refuse to recognize the storage units/buffers as inventory peripherals, while they recognize any other machine.

Steps to Reproduce
Steps to reproduce the behavior:

  1. Place down an Advanced Computer (the bug reproduces with a regular Computer and Wired Modem too)
  2. Place down a Basic Storage Unit on any of computer's sides
  3. Open the computer's interface, type "peripherals" into the terminal and press Enter. This command displays all peripherals that are attached to the computer
  4. See that the command prints "None" under "Attached peripherals", meaning that the computer doesn't recognize the Storage Unit as a peripheral.
  5. Repeat the steps 2-4 with any other block other than a Storage Unit/Buffer and see that the computer does recognize them as an inventory peripheral.

Screenshots

(sorry for low video quality, GitHub limits file size to 10 MB)

video_crf39.mp4

Environment:

  • Minecraft: 1.20.4
  • Mod Loader: Fabric 0.15.11
  • Mods:
    • Fabric API: 0.97.1 1.20.4
    • Reborn Core: 5.10.4
    • Tech Reborn: 5.10.4
    • CC Tweaked: 1.110.2 1.20.4

Logs
latest.log

Additional context
I've filed this issue here and not on CC: Tweaked's GitHub because its inventory peripheral system is generic and already works on any other block, so I think this is Tech Reborn's problem and not CC's; I can still file an issue on CC's GitHub if this turns out to be a CC bug or if you want me to.

commented

The way the stroage block works is quire diffrent, as it can store a large amount of items it doesnt expose its entire inventory like other blocks. To properly fix this I would expect it would require some custom support.

I imagine your goal is to be able to read how many of what item are stored?

commented

The way the stroage block works is quire diffrent, as it can store a large amount of items it doesnt expose its entire inventory like other blocks. To properly fix this I would expect it would require some custom support.

Yeah, now that I think about it, since CC's inventory api operates on a per-slot basis, exposing the entire Storage Unit inventory like a list of stacks of 64 items would be very inefficient. I wonder if it would be possible to at least allow pushing items into the input slot and pulling them from the output slot, that already works for the Tank Units?

I imagine your goal is to be able to read how many of what item are stored?

Well the inventory api allows not only querying items but also transferring them between the inventories, even remotely through CC's networking cables, allowing players to build an Applied Energistics-like storage system.

I also have 2 questions:

  1. Does the Fabric API (I think that's the part that allows CC to operate on generic inventory blocks?) allow more than 64 items to be in a single slot? If so, there could be a single slot in Storage Units that stores the entire item amount.
  2. Just for curiosity, what part of code is different for Storage Units compared to other blocks, that makes them not recognizable for CC? I'm bad at Java, but I haven't found the difference in how the Storage Units and Tank Units expose their 2 input/output slots.
commented

Holy, I've changed 2 lines of code in Tech Reborn's code it works! The items can be queried, pulled/pushed from/to the Storage Unit!

video_2pass_1443k.mp4

Since CC: Tweaked only works with SlottedStorage, and the StorageUnitBaseBlockEntity already implements the SlottedStorage API, I've just changed it so that its getExposedStorage returns CombinedSlottedStorage and getInternalStoreStorage returns SlottedStorage:

StorageUnitBaseBlockEntity_CombinedSlottedStorage.patch

diff --git a/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java b/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java
--- a/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java	(revision 7cfc8fb513bc34ddf27cfb7a0549ad3420b4623b)
+++ b/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java	(revision c1f650381a1f0ee3ac488b03d3cbdb33455878c4)
@@ -27,8 +27,9 @@
 import net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage;
 import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
 import net.fabricmc.fabric.api.transfer.v1.item.base.SingleStackStorage;
+import net.fabricmc.fabric.api.transfer.v1.storage.SlottedStorage;
 import net.fabricmc.fabric.api.transfer.v1.storage.Storage;
-import net.fabricmc.fabric.api.transfer.v1.storage.base.CombinedStorage;
+import net.fabricmc.fabric.api.transfer.v1.storage.base.CombinedSlottedStorage;
 import net.minecraft.block.BlockState;
 import net.minecraft.entity.player.PlayerEntity;
 import net.minecraft.item.ItemStack;
@@ -532,7 +533,7 @@
 		storeItemStack = ItemStack.fromNbt(tag);
 	}
 
-	private Storage<ItemVariant> getInternalStoreStorage(@Nullable Direction direction) {
+	private SlottedStorage<ItemVariant> getInternalStoreStorage(@Nullable Direction direction) {
 		// Quick fix to handle null sides. https://github.com/TechReborn/TechReborn/issues/3175
 		final Direction side = direction != null ? direction : Direction.DOWN;
 
@@ -581,7 +582,7 @@
 	}
 
 	public Storage<ItemVariant> getExposedStorage(Direction side) {
-		return new CombinedStorage<>(List.of(
+		return new CombinedSlottedStorage<>(List.of(
 				getInternalStoreStorage(side),
 				InventoryStorage.of(this, side)
 		));

I have no idea if this breaks anything, @modmuss50 thoughts?

commented

I think this change is fine, it does mean expopsing the large internal stack but it should be fine. Il will go ahead and make this change.