Fabric API

Fabric API

108M Downloads

Hopper item transfer changed

Krebs-Cycle opened this issue ยท 4 comments

commented

Fabric API version: 0.38.0 and 0.38.1
1.16.5

While testing the pulse extender shown here, I noticed that the item going into the top hopper the comparator was reading from was only remaining in the hopper for <1gt (Briefly appeared and disappeared in hopper. Never appeared in hopper when tick stepping with carpet) instead of the 7gt that I saw when I downgraded to version 0.37.2. It seems like this change could be related to #1639.

commented

Thanks for the report, as this is a critical issue I have marked the affected builds as beta, for now please use 0.37.2.

commented

Hi, @Krebs-Cycle im not the best with redstone so would struggle to reproduce and validate a possible fix that I have made (Thanks to @haykam for noticing it). If you have a spare few mins would you mind testing fabric-api-0.38.2+local-1.16.jar to see if it fixes this issue?

Many thanks.

1.17 diff

Index: fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java	(revision d19fec74a7a4ac74d03c252fcaff2171dbba5d2d)
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java	(date 1629501248429)
@@ -75,7 +75,7 @@
 	}
 
 	private static boolean doTransfer(Storage<ItemVariant> from, Storage<ItemVariant> to, @Nullable Object invFrom, @Nullable Object invTo) {
-		if (invFrom instanceof HopperBlockEntityAccessor hopperFrom && invTo instanceof HopperBlockEntityAccessor hopperTo) {
+		if (invFrom instanceof HopperBlockEntityAccessor hopperFrom && invTo instanceof HopperBlockEntityAccessor hopperTo && !hopperTo.fabric_isDisabled()) {
 			// Hoppers have some special interactions (see HopperBlockEntity#transfer)
 			boolean wasEmpty = hopperTo.isEmpty();
 			boolean moved = StorageUtil.move(from, to, k -> true, 1, null) == 1;
Index: fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java	(revision d19fec74a7a4ac74d03c252fcaff2171dbba5d2d)
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java	(date 1629501248435)
@@ -31,6 +31,9 @@
 	@Invoker("setCooldown")
 	void fabric_callSetCooldown(int cooldown);
 
+	@Invoker("isDisabled")
+	boolean fabric_isDisabled();
+
 	@Accessor("lastTickTime")
 	long fabric_getLastTickTime();
 }

1.16 diff

Index: fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java	(revision 08a8b4b11a6c4fa22a03935fa21877a79943f7d1)
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityAccessor.java	(date 1629501557875)
@@ -31,6 +31,9 @@
 	@Invoker("setCooldown")
 	void fabric_callSetCooldown(int cooldown);
 
+	@Invoker("isDisabled")
+	boolean fabric_isDisabled();
+
 	@Accessor("lastTickTime")
 	long fabric_getLastTickTime();
 }
Index: fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java	(revision 08a8b4b11a6c4fa22a03935fa21877a79943f7d1)
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/mixin/transfer/HopperBlockEntityMixin.java	(date 1629501576264)
@@ -88,17 +88,20 @@
 		if (invFrom instanceof HopperBlockEntityAccessor && invTo instanceof HopperBlockEntityAccessor) {
 			HopperBlockEntityAccessor hopperFrom = (HopperBlockEntityAccessor) invFrom;
 			HopperBlockEntityAccessor hopperTo = (HopperBlockEntityAccessor) invTo;
-			// Hoppers have some special interactions (see HopperBlockEntity#transfer)
-			boolean wasEmpty = hopperTo.isEmpty();
-			boolean moved = StorageUtil.move(from, to, k -> true, 1, null) == 1;
+
+			if (!hopperTo.fabric_isDisabled()) {
+				// Hoppers have some special interactions (see HopperBlockEntity#transfer)
+				boolean wasEmpty = hopperTo.isEmpty();
+				boolean moved = StorageUtil.move(from, to, k -> true, 1, null) == 1;
 
-			if (moved && wasEmpty && hopperTo.fabric_getLastTickTime() >= hopperFrom.fabric_getLastTickTime()) {
-				hopperTo.fabric_callSetCooldown(7);
-			}
+				if (moved && wasEmpty && hopperTo.fabric_getLastTickTime() >= hopperFrom.fabric_getLastTickTime()) {
+					hopperTo.fabric_callSetCooldown(7);
+				}
 
-			return moved;
-		} else {
-			return StorageUtil.move(from, to, k -> true, 1, null) == 1;
-		}
+				return moved;
+			}
+		}
+
+		return StorageUtil.move(from, to, k -> true, 1, null) == 1;
 	}
 }
commented

I just tried the version you sent and it still has the same problem. The item only briefly appears in the hopper and immediately gets pushed back into the dropper.

commented

Thanks for testing. Going to look at this more tomorrow ๐Ÿ‘