diff --git a/common/src/main/java/juuxel/adorn/block/property/OptionalProperty.java b/common/src/main/java/juuxel/adorn/block/property/OptionalProperty.java index c87ab6a53..318cb7488 100644 --- a/common/src/main/java/juuxel/adorn/block/property/OptionalProperty.java +++ b/common/src/main/java/juuxel/adorn/block/property/OptionalProperty.java @@ -45,8 +45,7 @@ public Collection> getValues() { @Override public String name(Value value) { - // TODO: Use pattern matching - return value instanceof Value.Some some ? some.value.asString() : NONE_NAME; + return value instanceof Value.Some(T inner) ? inner.asString() : NONE_NAME; } public EnumProperty getDelegate() { @@ -76,13 +75,11 @@ public boolean isPresent() { } @Override - public int compareTo(OptionalProperty.Value o) { - // TODO: Use pattern matching - if (o instanceof Some other) { - return value.compareTo(other.value); - } - - return 1; + public int compareTo(Value o) { + return switch (o) { + case Some(var otherValue) -> value.compareTo(otherValue); + case None none -> 1; + }; } } @@ -98,7 +95,7 @@ public boolean isPresent() { } @Override - public int compareTo(OptionalProperty.Value o) { + public int compareTo(Value o) { return o instanceof None ? 0 : -1; } } diff --git a/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java b/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java index 499a00e37..8779255fe 100644 --- a/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java +++ b/common/src/main/java/juuxel/adorn/compat/emi/AdornEmiPlugin.java @@ -12,13 +12,9 @@ import juuxel.adorn.recipe.AdornRecipes; import juuxel.adorn.recipe.FluidBrewingRecipe; import juuxel.adorn.recipe.ItemBrewingRecipe; -import juuxel.adorn.util.Logging; -import org.slf4j.Logger; @EmiEntrypoint public final class AdornEmiPlugin implements EmiPlugin { - private static final Logger LOGGER = Logging.logger(); - public static final EmiRecipeCategory BREWER_CATEGORY = new EmiRecipeCategory( AdornCommon.id("brewer"), EmiStack.of(AdornBlocks.INSTANCE.getBREWER()), @@ -33,16 +29,10 @@ public void register(EmiRegistry registry) { var recipeManager = registry.getRecipeManager(); for (var entry : recipeManager.listAllOfType(AdornRecipes.BREWING_TYPE.get())) { - BrewingEmiRecipe emiRecipe; - // TODO: Pattern matching - if (entry.value() instanceof ItemBrewingRecipe recipe) { - emiRecipe = new BrewingEmiRecipe(entry.id(), recipe); - } else if (entry.value() instanceof FluidBrewingRecipe recipe) { - emiRecipe = new BrewingEmiRecipe(entry.id(), recipe); - } else { - LOGGER.error("Unknown brewing recipe: {}", entry.value()); - continue; - } + BrewingEmiRecipe emiRecipe = switch (entry.value()) { + case ItemBrewingRecipe recipe -> new BrewingEmiRecipe(entry.id(), recipe); + case FluidBrewingRecipe recipe -> new BrewingEmiRecipe(entry.id(), recipe); + }; registry.addRecipe(emiRecipe); } diff --git a/common/src/main/java/juuxel/adorn/compat/jei/BrewerCategory.java b/common/src/main/java/juuxel/adorn/compat/jei/BrewerCategory.java index ad0812168..81680e2e9 100644 --- a/common/src/main/java/juuxel/adorn/compat/jei/BrewerCategory.java +++ b/common/src/main/java/juuxel/adorn/compat/jei/BrewerCategory.java @@ -69,16 +69,15 @@ public void setRecipe(IRecipeLayoutBuilder layoutBuilder, BrewingRecipe recipe, .setFluidRenderer(capacity, false, 16, BrewerScreen.FLUID_AREA_HEIGHT) .setOverlay(guiHelper.createDrawable(TEXTURE, 154, 17, 16, BrewerScreen.FLUID_AREA_HEIGHT), 0, 0); - if (recipe instanceof ItemBrewingRecipe r) { - firstSlot.addIngredients(r.firstIngredient()); - secondSlot.addIngredients(r.secondIngredient()); - resultSlot.addItemStack(r.result()); - } else if (recipe instanceof FluidBrewingRecipe r) { - firstSlot.addIngredients(r.firstIngredient()); - secondSlot.addIngredients(r.secondIngredient()); - resultSlot.addItemStack(r.result()); + if (recipe instanceof ItemBrewingRecipe(var firstIngredient, var secondIngredient, var result)) { + firstSlot.addIngredients(firstIngredient); + secondSlot.addIngredients(secondIngredient); + resultSlot.addItemStack(result); + } else if (recipe instanceof FluidBrewingRecipe(var firstIngredient, var secondIngredient, var ingredient, var result)) { + firstSlot.addIngredients(firstIngredient); + secondSlot.addIngredients(secondIngredient); + resultSlot.addItemStack(result); - var ingredient = r.fluid(); var amount = FluidUnit.convert(ingredient.getAmount(), ingredient.getUnit(), FluidBridge.get().getFluidUnit()); for (Fluid fluid : ingredient.fluid().getFluids()) { tank.addFluidStack(fluid, amount, ingredient.nbt()); diff --git a/common/src/main/java/juuxel/adorn/fluid/FluidKeyImpl.java b/common/src/main/java/juuxel/adorn/fluid/FluidKeyImpl.java index 67910579d..943912d6b 100644 --- a/common/src/main/java/juuxel/adorn/fluid/FluidKeyImpl.java +++ b/common/src/main/java/juuxel/adorn/fluid/FluidKeyImpl.java @@ -51,14 +51,9 @@ public String toString() { ).xmap( // TODO (Java 21): Use pattern matching either -> either.map(Function.identity(), Function.identity()), - key -> { - if (key instanceof Simple simple) { - return Either.left(simple); - } else if (key instanceof OfArray ofArray) { - return Either.right(ofArray); - } else { - throw new IllegalArgumentException(); - } + key -> switch (key) { + case Simple simple -> Either.left(simple); + case OfArray ofArray -> Either.right(ofArray); } ); diff --git a/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java b/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java index 8998579ac..2ad1224e2 100644 --- a/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java +++ b/common/src/main/java/juuxel/adorn/recipe/BrewingRecipe.java @@ -3,7 +3,7 @@ import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeType; -public interface BrewingRecipe extends Recipe { +public sealed interface BrewingRecipe extends Recipe permits FluidBrewingRecipe, ItemBrewingRecipe { @Override default RecipeType getType() { return AdornRecipes.BREWING_TYPE.get();