Skip to content

Commit 5927b47

Browse files
committed
Fix fluid helper crashes on empty fluid handler resources
1 parent 28eac40 commit 5927b47

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

loader-neoforge/src/main/java/org/cyclops/cyclopscore/helper/FluidHelpersNeoForge.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public long getCapacity(@Nullable ResourceHandler<FluidResource> fluidHandler) {
6464
long capacity = 0;
6565
if (fluidHandler != null) {
6666
for (int i = 0; i < fluidHandler.size(); i++) {
67-
capacity += fluidHandler.getCapacityAsLong(i, fluidHandler.getResource(i));
67+
FluidResource resource = fluidHandler.getResource(i);
68+
if (!resource.isEmpty()) {
69+
capacity += fluidHandler.getCapacityAsLong(i, resource);
70+
}
6871
}
6972
}
7073
return capacity;
@@ -156,8 +159,11 @@ public FluidStack placeOrPickUpFluid(Player player, InteractionHand hand, Level
156159
public boolean canExtract(ResourceHandler<FluidResource> fluidHandler) {
157160
for(int index = 0; index < fluidHandler.size(); ++index) {
158161
try (var tx = Transaction.openRoot()) {
159-
if (fluidHandler.extract(index, fluidHandler.getResource(index), Integer.MAX_VALUE, tx) > 0) {
160-
return true;
162+
FluidResource resource = fluidHandler.getResource(index);
163+
if (!resource.isEmpty()) {
164+
if (fluidHandler.extract(index, resource, Integer.MAX_VALUE, tx) > 0) {
165+
return true;
166+
}
161167
}
162168
}
163169
}

0 commit comments

Comments
 (0)