From 11cb0d7469e93f85c39f23b46ae74886289cbee6 Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Tue, 2 Jul 2024 21:42:56 +0200 Subject: [PATCH] fix: Fix more JEI support --- .../compat/jei/ExpandedHeavySieveRecipe.java | 22 +++++++++---------- .../jei/HeavySieveJeiRecipeCategory.java | 14 +++++++----- .../forge/compat/jei/JEIAddon.java | 1 + .../forge/compat/jei/JeiUtils.java | 8 +++---- .../jei/WoodenCrucibleJeiRecipeCategory.java | 12 +++++----- .../excompressum/loot/LootTableUtils.java | 12 +++++----- 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedHeavySieveRecipe.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedHeavySieveRecipe.java index 2c0e65a1..b317ae3f 100644 --- a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedHeavySieveRecipe.java +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedHeavySieveRecipe.java @@ -8,6 +8,7 @@ import net.blay09.mods.excompressum.loot.MergedLootTableEntry; import net.blay09.mods.excompressum.registry.sievemesh.SieveMeshRegistry; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; import java.util.*; import java.util.stream.Collectors; @@ -15,25 +16,23 @@ public class ExpandedHeavySieveRecipe { private final HeavySieveRecipe recipe; - private final List> inputs; + private final Ingredient ingredient; + private final List meshItems; private final List outputs; private final List outputItems; private final boolean waterlogged; public ExpandedHeavySieveRecipe(HeavySieveRecipe recipe) { this.recipe = recipe; - inputs = new ArrayList<>(); + meshItems = new ArrayList<>(); if (recipe.getMinimumMesh() != null) { SieveMeshRegistryEntry minimumMesh = SieveMeshRegistry.getEntry(recipe.getMinimumMesh()); - List meshItems = new ArrayList<>(); for (SieveMeshRegistryEntry mesh : SieveMeshRegistry.getEntries().values()) { if (mesh.getMeshLevel() >= minimumMesh.getMeshLevel()) { meshItems.add(mesh.getItemStack()); } } - inputs.add(meshItems); } else if (recipe.getMeshes() != null) { - List meshItems = new ArrayList<>(); for (CommonMeshType meshType : recipe.getMeshes()) { for (SieveMeshRegistryEntry mesh : SieveMeshRegistry.getEntries().values()) { if (mesh.getMeshType() == meshType) { @@ -41,11 +40,8 @@ public ExpandedHeavySieveRecipe(HeavySieveRecipe recipe) { } } } - inputs.add(meshItems); - } else { - inputs.add(Collections.emptyList()); } - inputs.add(Arrays.asList(recipe.getIngredient().getItems())); + ingredient = recipe.getIngredient(); List entries = LootTableUtils.getLootTableEntries(recipe.getLootTable()); outputs = LootTableUtils.mergeLootTableEntries(entries); outputItems = outputs.stream().map(MergedLootTableEntry::getItemStack).collect(Collectors.toList()); @@ -56,8 +52,12 @@ public HeavySieveRecipe getRecipe() { return recipe; } - public List> getInputs() { - return inputs; + public Ingredient getIngredient() { + return ingredient; + } + + public List getMeshItems() { + return meshItems; } public List getOutputs() { diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/HeavySieveJeiRecipeCategory.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/HeavySieveJeiRecipeCategory.java index 22ffb59e..9f1cdcca 100644 --- a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/HeavySieveJeiRecipeCategory.java +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/HeavySieveJeiRecipeCategory.java @@ -16,6 +16,7 @@ import net.minecraft.world.item.ItemStack; import javax.annotation.Nonnull; +import java.util.List; public class HeavySieveJeiRecipeCategory implements IRecipeCategory { @@ -56,12 +57,13 @@ public IDrawable getIcon() { @Override public void setRecipe(IRecipeLayoutBuilder recipeLayoutBuilder, ExpandedHeavySieveRecipe recipe, IFocusGroup focusGroup) { - recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 62, 10); - recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 88, 10); - for (int i = 0; i < recipe.getOutputItems().size(); i++) { - final int slotX = 3 + i * 18; - final int slotY = 37; - recipeLayoutBuilder.addSlot(RecipeIngredientRole.OUTPUT, slotX, slotY); + recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 62, 10).addIngredients(recipe.getIngredient()); + recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, 88, 10).addItemStacks(recipe.getMeshItems()); + final var outputItems = recipe.getOutputItems(); + for (int i = 0; i < outputItems.size(); i++) { + final int slotX = 3 + (i % 9 * 18); + final int slotY = 37 + (i / 9 * 18); + recipeLayoutBuilder.addSlot(RecipeIngredientRole.OUTPUT, slotX, slotY).addItemStack(outputItems.get(i)); } } diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JEIAddon.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JEIAddon.java index 0e17f613..f5d4e527 100644 --- a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JEIAddon.java +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JEIAddon.java @@ -141,6 +141,7 @@ private void loadGeneratedHeavySieveRecipe(Level level, boolean waterlogged, Gen @Override public void registerRecipeCatalysts(IRecipeCatalystRegistration registry) { + registry.addRecipeCatalyst(new ItemStack(ModBlocks.autoHeavySieve), HeavySieveJeiRecipeCategory.TYPE); for (final var heavySieve : ModBlocks.heavySieves) { registry.addRecipeCatalyst(new ItemStack(heavySieve), HeavySieveJeiRecipeCategory.TYPE); } diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JeiUtils.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JeiUtils.java index 7c82a7a7..28727ab8 100644 --- a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JeiUtils.java +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/JeiUtils.java @@ -35,12 +35,12 @@ private static String formatChance(LootTableEntry entry) { private static Component getCountTextComponent(LootTableEntry entry) { if (entry.getCountRange() instanceof UniformGeneratorAccessor uniform) { - int min = LootTableUtils.getMinCount(uniform.getMin()); - int max = LootTableUtils.getMaxCount(uniform.getMax()); + int min = (int) LootTableUtils.getMinCount(uniform.getMin()); + int max = (int) LootTableUtils.getMaxCount(uniform.getMax()); return Component.translatable("tooltip.jei.drop_count.random_range", min, max); } else if (entry.getCountRange() instanceof BinomialDistributionGeneratorAccessor binomial) { - int n = LootTableUtils.getMinCount(binomial.getN()); - int p = LootTableUtils.getMinCount(binomial.getP()); + int n = (int) LootTableUtils.getMinCount(binomial.getN()); + int p = (int) LootTableUtils.getMinCount(binomial.getP()); return Component.translatable("tooltip.jei.drop_count.binomial_range", n * p); } else if (entry.getCountRange() instanceof ConstantValueAccessor constant) { return Component.translatable("tooltip.jei.drop_count.constant", (int) constant.getValue()); diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/WoodenCrucibleJeiRecipeCategory.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/WoodenCrucibleJeiRecipeCategory.java index f36362a6..fe8fb0e2 100644 --- a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/WoodenCrucibleJeiRecipeCategory.java +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/WoodenCrucibleJeiRecipeCategory.java @@ -15,6 +15,7 @@ import net.minecraft.world.item.ItemStack; import javax.annotation.Nonnull; +import java.util.List; public class WoodenCrucibleJeiRecipeCategory implements IRecipeCategory { @@ -57,12 +58,11 @@ public IDrawable getIcon() { public void setRecipe(IRecipeLayoutBuilder recipeLayoutBuilder, ExpandedWoodenCrucibleRecipe recipe, IFocusGroup focusGroup) { recipeLayoutBuilder.addSlot(RecipeIngredientRole.OUTPUT, 75, 10).addFluidStack(recipe.getFluid(), recipe.getFluidStack().getAmount()); - int slotNumber = 0; - for (final var itemStack : recipe.getInputs()) { - final int slotX = 3 + (slotNumber % 9 * 18); - final int slotY = 37 + (slotNumber / 9 * 18); - recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, slotX, slotY).addItemStack(itemStack); - slotNumber++; + final var inputs = recipe.getInputs(); + for (int i = 0; i < inputs.size(); i++) { + final int slotX = 3 + (i % 9 * 18); + final int slotY = 37 + (i / 9 * 18); + recipeLayoutBuilder.addSlot(RecipeIngredientRole.INPUT, slotX, slotY).addItemStack(inputs.get(i)); } } diff --git a/shared/src/main/java/net/blay09/mods/excompressum/loot/LootTableUtils.java b/shared/src/main/java/net/blay09/mods/excompressum/loot/LootTableUtils.java index 0a63e45f..105eaf4c 100644 --- a/shared/src/main/java/net/blay09/mods/excompressum/loot/LootTableUtils.java +++ b/shared/src/main/java/net/blay09/mods/excompressum/loot/LootTableUtils.java @@ -56,13 +56,13 @@ public static List getLootTableEntries(@Nullable LootTable lootT NumberProvider countRange = getCountRange(entry); if (entry instanceof LootItemAccessor lootItem) { ItemStack itemStack = new ItemStack(lootItem.getItem()); - itemStack.setCount(getMaxCount(countRange)); + itemStack.setCount(Math.max(1, (int) getMaxCount(countRange))); result.add(new LootTableEntry(itemStack, countRange, baseChance)); } else if (entry instanceof TagEntryAccessor tagEntry) { TagKey tag = tagEntry.getTag(); BuiltInRegistries.ITEM.getOrCreateTag(tag).forEach(itemHolder -> { ItemStack itemStack = new ItemStack(itemHolder.value()); - itemStack.setCount(getMaxCount(countRange)); + itemStack.setCount(Math.max(1, (int) getMaxCount(countRange))); result.add(new LootTableEntry(itemStack, countRange, baseChance)); }); } @@ -100,25 +100,25 @@ private static NumberProvider getCountRange(LootPoolEntryContainer entry) { return ConstantValue.exactly(1); } - public static int getMinCount(NumberProvider range) { + public static float getMinCount(NumberProvider range) { if (range instanceof UniformGeneratorAccessor uniform) { return getMinCount(uniform.getMin()); } else if (range instanceof BinomialDistributionGeneratorAccessor binomial) { return getMinCount(binomial.getN()) * getMaxCount(binomial.getP()); } else if (range instanceof ConstantValueAccessor constant) { - return (int) constant.getValue(); + return constant.getValue(); } return 1; } - public static int getMaxCount(NumberProvider range) { + public static float getMaxCount(NumberProvider range) { if (range instanceof UniformGeneratorAccessor uniform) { return getMaxCount(uniform.getMax()); } else if (range instanceof BinomialDistributionGeneratorAccessor binomial) { return getMaxCount(binomial.getN()) * getMaxCount(binomial.getP()); } else if (range instanceof ConstantValueAccessor constant) { - return (int) constant.getValue(); + return constant.getValue(); } return 1;