From 2efbfb676f7354de28b495bf145881dcc0eab0de Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Sun, 5 Jan 2025 16:27:56 -0800 Subject: [PATCH] Fixed Fluid Transformation recipes requiring byproducts --- changelog.md | 1 + .../java/thedarkcolour/exdeorum/recipe/WeightedList.java | 7 +++++++ .../exdeorum/recipe/barrel/FluidTransformationRecipe.java | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 78539f37..33ec6a5c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ ## Ex Deorum 3.5 - Remove Yellorium Dust sieve drop (#116) +- Fixed Fluid Transformation recipes requiring byproducts ## Ex Deorum 3.4 - Fix JEI bug with sieve recipes overflowing due to JEI API changes diff --git a/src/main/java/thedarkcolour/exdeorum/recipe/WeightedList.java b/src/main/java/thedarkcolour/exdeorum/recipe/WeightedList.java index 2ed8b400..f121054c 100644 --- a/src/main/java/thedarkcolour/exdeorum/recipe/WeightedList.java +++ b/src/main/java/thedarkcolour/exdeorum/recipe/WeightedList.java @@ -34,6 +34,8 @@ import java.util.function.Function; // much simpler version of SimpleWeightedRandomList that supports .equals public class WeightedList { + private static final WeightedList EMPTY = new WeightedList<>(0, new Object[0], new int[0]); + private final int totalWeight; private final Object[] values; private final int[] weights; @@ -134,6 +136,11 @@ public class WeightedList { return new Builder<>(); } + @SuppressWarnings("unchecked") + public static WeightedList empty() { + return (WeightedList) EMPTY; + } + public static class Builder { private final ArrayList values = new ArrayList<>(); private final IntArrayList weights = new IntArrayList(); diff --git a/src/main/java/thedarkcolour/exdeorum/recipe/barrel/FluidTransformationRecipe.java b/src/main/java/thedarkcolour/exdeorum/recipe/barrel/FluidTransformationRecipe.java index d4803bce..d16ffe37 100644 --- a/src/main/java/thedarkcolour/exdeorum/recipe/barrel/FluidTransformationRecipe.java +++ b/src/main/java/thedarkcolour/exdeorum/recipe/barrel/FluidTransformationRecipe.java @@ -57,7 +57,7 @@ public record FluidTransformationRecipe( CodecUtil.fluidField("result_fluid", FluidTransformationRecipe::resultFluid), Codec.INT.fieldOf("result_color").forGetter(FluidTransformationRecipe::resultColor), BlockPredicate.CODEC.fieldOf("catalyst").forGetter(FluidTransformationRecipe::catalyst), - WeightedList.codec(Codec.STRING.xmap(RecipeUtil::parseBlockState, RecipeUtil::writeBlockState)).fieldOf("byproducts").forGetter(FluidTransformationRecipe::byproducts), + WeightedList.codec(Codec.STRING.xmap(RecipeUtil::parseBlockState, RecipeUtil::writeBlockState)).optionalFieldOf("byproducts", WeightedList.empty()).forGetter(FluidTransformationRecipe::byproducts), Codec.INT.fieldOf("duration").forGetter(FluidTransformationRecipe::duration) ).apply(instance, FluidTransformationRecipe::new)); public static final StreamCodec STREAM_CODEC = StreamCodec.of(FluidTransformationRecipe::toNetwork, FluidTransformationRecipe::fromNetwork);