1212import dan200 .computercraft .shared .platform .RegistryWrappers ;
1313import dan200 .computercraft .shared .util .CapabilityUtil ;
1414import net .minecraft .world .level .block .entity .BlockEntity ;
15+ import net .minecraft .world .level .material .Fluid ;
1516import net .minecraftforge .common .capabilities .ForgeCapabilities ;
1617import net .minecraftforge .common .capabilities .ICapabilityProvider ;
1718import net .minecraftforge .fluids .FluidStack ;
@@ -63,7 +64,7 @@ public int pushFluid(
6364
6465 return fluid == null
6566 ? moveFluid (from , actualLimit , to )
66- : moveFluid (from , new FluidStack ( fluid , actualLimit ) , to );
67+ : moveFluid (from , fluid , actualLimit , to );
6768 }
6869
6970 @ Override
@@ -88,7 +89,7 @@ public int pullFluid(
8889
8990 return fluid == null
9091 ? moveFluid (from , actualLimit , to )
91- : moveFluid (from , new FluidStack ( fluid , actualLimit ) , to );
92+ : moveFluid (from , fluid , actualLimit , to );
9293 }
9394
9495 @ Nullable
@@ -108,7 +109,7 @@ private static IFluidHandler extractHandler(IPeripheral peripheral) {
108109 }
109110
110111 /**
111- * Move fluid from one handler to another.
112+ * Move any fluid from one handler to another.
112113 *
113114 * @param from The handler to move from.
114115 * @param limit The maximum amount of fluid to move.
@@ -120,15 +121,26 @@ private static int moveFluid(IFluidHandler from, int limit, IFluidHandler to) {
120121 }
121122
122123 /**
123- * Move fluid from one handler to another.
124+ * Move a specific fluid from one handler to another.
124125 *
125126 * @param from The handler to move from.
126- * @param fluid The fluid and limit to move.
127+ * @param fluid The fluid to move.
128+ * @param limit The maximum amount of fluid to move.
127129 * @param to The handler to move to.
128130 * @return The amount of fluid moved.
129131 */
130- private static int moveFluid (IFluidHandler from , FluidStack fluid , IFluidHandler to ) {
131- return moveFluid (from , from .drain (fluid , IFluidHandler .FluidAction .SIMULATE ), fluid .getAmount (), to );
132+ private static int moveFluid (IFluidHandler from , Fluid fluid , int limit , IFluidHandler to ) {
133+ // Rather than constructing the FluidStack directly, we try to find a matching fluid (but with possibly
134+ // different NBT components) in the tank.
135+ for (int i = 0 , len = from .getTanks (); i < len ; i ++) {
136+ var currentFluid = from .getFluidInTank (i );
137+ if (currentFluid .getFluid () != fluid ) continue ;
138+
139+ var extracted = from .drain (currentFluid , IFluidHandler .FluidAction .SIMULATE );
140+ if (!extracted .isEmpty ()) return moveFluid (from , extracted , limit , to );
141+ }
142+
143+ return 0 ;
132144 }
133145
134146 /**
@@ -141,7 +153,7 @@ private static int moveFluid(IFluidHandler from, FluidStack fluid, IFluidHandler
141153 * @return The amount of fluid moved.
142154 */
143155 private static int moveFluid (IFluidHandler from , FluidStack extracted , int limit , IFluidHandler to ) {
144- if (extracted .getAmount () <= 0 ) return 0 ;
156+ if (extracted .isEmpty () ) return 0 ;
145157
146158 // Limit the amount to extract.
147159 extracted = extracted .copy ();
0 commit comments