Skip to content

Commit

Permalink
Fixed FluidStack amount parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jul 24, 2024
1 parent dca1a11 commit 6375e00
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/main/java/dev/latvian/mods/kubejs/fluid/FluidWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,7 @@ static FluidStack read(DynamicOps<Tag> registryOps, StringReader reader) throws
return FluidStack.EMPTY;
}

int amount = 1;

if (reader.canRead() && StringReader.isAllowedNumber(reader.peek())) {
amount = Mth.ceil(reader.readDouble());
reader.skipWhitespace();
reader.expect('x');
reader.skipWhitespace();

if (amount < 1) {
throw new IllegalArgumentException("Item count smaller than 1 is not allowed!");
}
}

int amount = readFluidAmount(reader);
var fluidId = ResourceLocation.read(reader);
var fluidStack = new FluidStack(BuiltInRegistries.FLUID.get(fluidId), amount);

Expand Down Expand Up @@ -278,9 +266,12 @@ static SizedFluidIngredient readSizedIngredient(DynamicOps<Tag> registryOps, Str
return EMPTY_SIZED;
}

int amount = FluidType.BUCKET_VOLUME;
int amount = readFluidAmount(reader);
return new SizedFluidIngredient(readIngredient(registryOps, reader), amount);
}

if (StringReader.isAllowedNumber(reader.peek())) {
static int readFluidAmount(StringReader reader) throws CommandSyntaxException {
if (reader.canRead() && StringReader.isAllowedNumber(reader.peek())) {
var amountd = reader.readDouble();
reader.skipWhitespace();

Expand All @@ -296,15 +287,17 @@ static SizedFluidIngredient readSizedIngredient(DynamicOps<Tag> registryOps, Str
amountd = amountd / reader.readDouble();
}

amount = Mth.ceil(amountd);
int amount = Mth.ceil(amountd);
reader.expect('x');
reader.skipWhitespace();

if (amount < 1) {
throw new IllegalArgumentException("SizedFluidIngredient amount smaller than 1 is not allowed!");
throw new IllegalArgumentException("Fluid amount smaller than 1 is not allowed!");
}

return amount;
}

return new SizedFluidIngredient(readIngredient(registryOps, reader), amount);
return FluidType.BUCKET_VOLUME;
}
}

0 comments on commit 6375e00

Please sign in to comment.