Merge pull request #6952 from IThundxr/mc1.18/fluidstack-ingredient-crash-fix

Better FluidIngredient exception handling
This commit is contained in:
simibubi 2024-10-23 21:53:31 +02:00 committed by GitHub
commit d39f89983a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -53,11 +53,11 @@ public class FluidHelper {
public static boolean isLava(Fluid fluid) {
return convertToStill(fluid) == Fluids.LAVA;
}
public static boolean isSame(FluidStack fluidStack, FluidStack fluidStack2) {
return fluidStack.getFluid() == fluidStack2.getFluid();
}
public static boolean isSame(FluidStack fluidStack, Fluid fluid) {
return fluidStack.getFluid() == fluid;
}
@ -147,6 +147,8 @@ public class FluidHelper {
Fluid fluid = ForgeRegistries.FLUIDS.getValue(id);
if (fluid == null)
throw new JsonSyntaxException("Unknown fluid '" + id + "'");
if (fluid == Fluids.EMPTY)
throw new JsonSyntaxException("Invalid empty fluid '" + id + "'");
int amount = GsonHelper.getAsInt(json, "amount");
FluidStack stack = new FluidStack(fluid, amount);

View file

@ -124,7 +124,7 @@ public abstract class FluidIngredient implements Predicate<FluidStack> {
public static FluidIngredient deserialize(@Nullable JsonElement je) {
if (!isFluidIngredient(je))
throw new JsonSyntaxException("Invalid fluid ingredient: " + Objects.toString(je));
throw new JsonSyntaxException("Invalid fluid ingredient: " + je);
JsonObject json = je.getAsJsonObject();
FluidIngredient ingredient = json.has("fluidTag") ? new FluidTagIngredient() : new FluidStackIngredient();