Skip to content

Commit e1a085f

Browse files
authored
Fix IllegalArgumentException in DamageIndicatedItemFluidContainer.canDrain on empty container (#219)
Closes CyclopsMC/EvilCraft#1164
1 parent 1616828 commit e1a085f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

loader-neoforge/src/main/java/org/cyclops/cyclopscore/item/DamageIndicatedItemFluidContainer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ public boolean canDrain(int amount, ItemStack itemStack) {
120120
ItemAccess itemAccess = ItemAccess.forStack(itemStack);
121121
ResourceHandler<FluidResource> fluidHandler = itemAccess.getCapability(Capabilities.Fluid.ITEM);
122122
if (fluidHandler == null) return false;
123+
FluidResource resource = fluidHandler.getResource(0);
124+
// Avoid IllegalArgumentException when the fluid handler has no fluid (empty resource is not allowed in NeoForge extract calls)
125+
if (resource.isEmpty()) return false;
123126
try (var tx = Transaction.openRoot()) {
124-
int simulatedDrain = fluidHandler.extract(fluidHandler.getResource(0), amount, tx);
127+
int simulatedDrain = fluidHandler.extract(resource, amount, tx);
125128
return simulatedDrain == amount;
126129
}
127130
}

0 commit comments

Comments
 (0)