From 6bd2a3a6f21ad32b82a8ffa91ce96d9bda037677 Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Tue, 2 Jul 2024 21:50:19 +0200 Subject: [PATCH] fix: Fix more JEI support --- .../forge/compat/exdeorum/ExDeorumAddon.java | 28 ++++++- .../forge/compat/jei/ExpandedSieveRecipe.java | 76 +++++++++++++++++ .../forge/compat/jei/JEIAddon.java | 8 ++ .../compat/jei/SieveJeiRecipeCategory.java | 69 ++++++++++++++++ .../registry/sieve/SieveRecipeImpl.java | 81 +++++++++++++++++++ .../assets/excompressum/lang/en_us.json | 1 + 6 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedSieveRecipe.java create mode 100644 forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/SieveJeiRecipeCategory.java create mode 100644 shared/src/main/java/net/blay09/mods/excompressum/registry/sieve/SieveRecipeImpl.java diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/exdeorum/ExDeorumAddon.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/exdeorum/ExDeorumAddon.java index 2041e053..d8194832 100644 --- a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/exdeorum/ExDeorumAddon.java +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/exdeorum/ExDeorumAddon.java @@ -18,6 +18,7 @@ import net.blay09.mods.excompressum.registry.compressedhammer.CompressedHammerRecipeImpl; import net.blay09.mods.excompressum.registry.hammer.HammerRecipeImpl; import net.blay09.mods.excompressum.registry.heavysieve.HeavySieveRecipeImpl; +import net.blay09.mods.excompressum.registry.sieve.SieveRecipeImpl; import net.blay09.mods.excompressum.registry.sievemesh.SieveMeshRegistry; import net.blay09.mods.excompressum.utils.StupidUtils; import net.minecraft.core.BlockPos; @@ -309,7 +310,32 @@ public List getCompressedHammerRecipes() { @Override public List getSieveRecipes() { - return List.of(); + List result = new ArrayList<>(); + + final var recipeManager = ExCompressum.proxy.get().getRecipeManager(null); + ArrayListMultimap, thedarkcolour.exdeorum.recipe.sieve.SieveRecipe> groupedRecipes = ArrayListMultimap.create(); + final var sieveRecipes = recipeManager.getAllRecipesFor(ERecipeTypes.SIEVE.get()); + for (final var recipe : sieveRecipes) { + final var mesh = itemToMeshType.get(recipe.mesh); + groupedRecipes.put(Pair.of(recipe.getIngredient().getStackingIds(), mesh), recipe); + } + + for (final var packedStacks : groupedRecipes.keySet()) { + final var tableBuilder = LootTable.lootTable(); + for (final var recipe : groupedRecipes.get(packedStacks)) { + final var poolBuilder = LootPool.lootPool(); + final var entryBuilder = buildLootEntry(recipe.result, recipe.resultAmount); + poolBuilder.add(entryBuilder); + tableBuilder.withPool(poolBuilder); + } + + final var firstRecipe = groupedRecipes.get(packedStacks).get(0); + final var ingredient = firstRecipe.getIngredient(); + final var lootTable = tableBuilder.build(); + result.add(new SieveRecipeImpl(firstRecipe.getId(), ingredient, lootTable, false, packedStacks.getSecond(), null)); + } + + return result; } @Override diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedSieveRecipe.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedSieveRecipe.java new file mode 100644 index 00000000..90eb4e16 --- /dev/null +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/ExpandedSieveRecipe.java @@ -0,0 +1,76 @@ +package net.blay09.mods.excompressum.forge.compat.jei; + +import net.blay09.mods.excompressum.api.recipe.HeavySieveRecipe; +import net.blay09.mods.excompressum.api.recipe.SieveRecipe; +import net.blay09.mods.excompressum.api.sievemesh.CommonMeshType; +import net.blay09.mods.excompressum.api.sievemesh.SieveMeshRegistryEntry; +import net.blay09.mods.excompressum.loot.LootTableEntry; +import net.blay09.mods.excompressum.loot.LootTableUtils; +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.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class ExpandedSieveRecipe { + + private final SieveRecipe recipe; + private final Ingredient ingredient; + private final List meshItems; + private final List outputs; + private final List outputItems; + private final boolean waterlogged; + + public ExpandedSieveRecipe(SieveRecipe recipe) { + this.recipe = recipe; + meshItems = new ArrayList<>(); + if (recipe.getMinimumMesh() != null) { + SieveMeshRegistryEntry minimumMesh = SieveMeshRegistry.getEntry(recipe.getMinimumMesh()); + for (SieveMeshRegistryEntry mesh : SieveMeshRegistry.getEntries().values()) { + if (mesh.getMeshLevel() >= minimumMesh.getMeshLevel()) { + meshItems.add(mesh.getItemStack()); + } + } + } else if (recipe.getMeshes() != null) { + for (CommonMeshType meshType : recipe.getMeshes()) { + for (SieveMeshRegistryEntry mesh : SieveMeshRegistry.getEntries().values()) { + if (mesh.getMeshType() == meshType) { + meshItems.add(mesh.getItemStack()); + } + } + } + } + ingredient = recipe.getIngredient(); + List entries = LootTableUtils.getLootTableEntries(recipe.getLootTable()); + outputs = LootTableUtils.mergeLootTableEntries(entries); + outputItems = outputs.stream().map(MergedLootTableEntry::getItemStack).collect(Collectors.toList()); + waterlogged = recipe.isWaterlogged(); + } + + public SieveRecipe getRecipe() { + return recipe; + } + + public Ingredient getIngredient() { + return ingredient; + } + + public List getMeshItems() { + return meshItems; + } + + public List getOutputs() { + return outputs; + } + + public List getOutputItems() { + return outputItems; + } + + public boolean isWaterlogged() { + return waterlogged; + } +} 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 f5d4e527..27c4b3d4 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 @@ -59,6 +59,12 @@ public void registerRecipes(IRecipeRegistration registry) { registry.addRecipes(HeavySieveJeiRecipeCategory.TYPE, expandedHeavySieveRecipes); + final var expandedSieveRecipes = new ArrayList(); + for (final var recipe : ExNihilo.getInstance().getSieveRecipes()) { + expandedSieveRecipes.add(new ExpandedSieveRecipe(recipe)); + } + registry.addRecipes(SieveJeiRecipeCategory.TYPE, expandedSieveRecipes); + List expandedCompressedHammerRecipes = new ArrayList<>(); final var compressedHammerRecipes = recipeManager.getAllRecipesFor(ModRecipeTypes.compressedHammerRecipeType); for (final var recipe : compressedHammerRecipes) { @@ -141,6 +147,7 @@ private void loadGeneratedHeavySieveRecipe(Level level, boolean waterlogged, Gen @Override public void registerRecipeCatalysts(IRecipeCatalystRegistration registry) { + registry.addRecipeCatalyst(new ItemStack(ModBlocks.autoSieve), SieveJeiRecipeCategory.TYPE); registry.addRecipeCatalyst(new ItemStack(ModBlocks.autoHeavySieve), HeavySieveJeiRecipeCategory.TYPE); for (final var heavySieve : ModBlocks.heavySieves) { registry.addRecipeCatalyst(new ItemStack(heavySieve), HeavySieveJeiRecipeCategory.TYPE); @@ -169,6 +176,7 @@ public ResourceLocation getPluginUid() { @Override public void registerCategories(IRecipeCategoryRegistration registry) { registry.addRecipeCategories( + new SieveJeiRecipeCategory(registry.getJeiHelpers()), new HeavySieveJeiRecipeCategory(registry.getJeiHelpers()), new HammerJeiRecipeCategory(registry.getJeiHelpers().getGuiHelper()), new CompressedHammerJeiRecipeCategory(registry.getJeiHelpers().getGuiHelper()), diff --git a/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/SieveJeiRecipeCategory.java b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/SieveJeiRecipeCategory.java new file mode 100644 index 00000000..c2260437 --- /dev/null +++ b/forge/src/main/java/net/blay09/mods/excompressum/forge/compat/jei/SieveJeiRecipeCategory.java @@ -0,0 +1,69 @@ +package net.blay09.mods.excompressum.forge.compat.jei; + +import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.helpers.IGuiHelper; +import mezz.jei.api.helpers.IJeiHelpers; +import mezz.jei.api.recipe.IFocusGroup; +import mezz.jei.api.recipe.RecipeIngredientRole; +import mezz.jei.api.recipe.RecipeType; +import mezz.jei.api.recipe.category.IRecipeCategory; +import net.blay09.mods.excompressum.ExCompressum; +import net.blay09.mods.excompressum.block.ModBlocks; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; + +import javax.annotation.Nonnull; + +public class SieveJeiRecipeCategory implements IRecipeCategory { + + public static final ResourceLocation UID = new ResourceLocation(ExCompressum.MOD_ID, "sieve"); + public static final RecipeType TYPE = new RecipeType<>(UID, ExpandedSieveRecipe.class); + private static final ResourceLocation texture = new ResourceLocation(ExCompressum.MOD_ID, "textures/gui/jei_heavy_sieve.png"); + + private final IDrawable background; + private final IDrawable icon; + + public SieveJeiRecipeCategory(IJeiHelpers jeiHelpers) { + final IGuiHelper guiHelper = jeiHelpers.getGuiHelper(); + this.background = guiHelper.createDrawable(texture, 0, 0, 166, 129); + this.icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(ModBlocks.autoSieve)); + } + + @Override + public RecipeType getRecipeType() { + return TYPE; + } + + @Nonnull + @Override + public Component getTitle() { + return Component.translatable(UID.toString()); + } + + @Nonnull + @Override + public IDrawable getBackground() { + return background; + } + + @Override + public IDrawable getIcon() { + return icon; + } + + @Override + public void setRecipe(IRecipeLayoutBuilder recipeLayoutBuilder, ExpandedSieveRecipe recipe, IFocusGroup focusGroup) { + 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/shared/src/main/java/net/blay09/mods/excompressum/registry/sieve/SieveRecipeImpl.java b/shared/src/main/java/net/blay09/mods/excompressum/registry/sieve/SieveRecipeImpl.java new file mode 100644 index 00000000..a7029ebc --- /dev/null +++ b/shared/src/main/java/net/blay09/mods/excompressum/registry/sieve/SieveRecipeImpl.java @@ -0,0 +1,81 @@ +package net.blay09.mods.excompressum.registry.sieve; + +import net.blay09.mods.excompressum.api.recipe.HeavySieveRecipe; +import net.blay09.mods.excompressum.api.recipe.SieveRecipe; +import net.blay09.mods.excompressum.api.sievemesh.CommonMeshType; +import net.blay09.mods.excompressum.registry.ExCompressumRecipe; +import net.blay09.mods.excompressum.registry.ModRecipeTypes; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeSerializer; +import net.minecraft.world.level.storage.loot.LootTable; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; + +public class SieveRecipeImpl extends ExCompressumRecipe implements SieveRecipe { + + private Ingredient ingredient; + private LootTable lootTable; + private boolean waterlogged; + private CommonMeshType minimumMesh; + private Set meshes; + + public SieveRecipeImpl(ResourceLocation id, Ingredient ingredient, LootTable lootTable, boolean waterlogged, @Nullable CommonMeshType minimumMesh, @Nullable Set meshes) { + super(id, ModRecipeTypes.heavySieveRecipeType); + this.ingredient = ingredient; + this.lootTable = lootTable; + this.waterlogged = waterlogged; + this.minimumMesh = minimumMesh; + this.meshes = meshes; + } + + @Override + public RecipeSerializer getSerializer() { + return ModRecipeTypes.heavySieveRecipeSerializer; + } + + @Override + public Ingredient getIngredient() { + return ingredient; + } + + @Override + public LootTable getLootTable() { + return lootTable; + } + + public boolean isWaterlogged() { + return waterlogged; + } + + @Nullable + public CommonMeshType getMinimumMesh() { + return minimumMesh; + } + + @Nullable + public Set getMeshes() { + return meshes; + } + + public void setIngredient(Ingredient ingredient) { + this.ingredient = ingredient; + } + + public void setLootTable(LootTable lootTable) { + this.lootTable = lootTable; + } + + public void setWaterlogged(boolean waterlogged) { + this.waterlogged = waterlogged; + } + + public void setMinimumMesh(@Nullable CommonMeshType minimumMesh) { + this.minimumMesh = minimumMesh; + } + + public void setMeshes(@Nullable Set meshes) { + this.meshes = meshes; + } +} diff --git a/shared/src/main/resources/assets/excompressum/lang/en_us.json b/shared/src/main/resources/assets/excompressum/lang/en_us.json index 19dd4691..53a7ce84 100644 --- a/shared/src/main/resources/assets/excompressum/lang/en_us.json +++ b/shared/src/main/resources/assets/excompressum/lang/en_us.json @@ -123,6 +123,7 @@ "excompressum:wooden_crucible": "Wooden Crucible", "excompressum:hammer": "Hammer", "excompressum:compressed_hammer": "Compressed Hammer", + "excompressum:sieve": "Sieve", "excompressum:heavy_sieve": "Heavy Sieve", "excompressum:chicken_stick": "Chicken Stick" }