Skip to content

Commit

Permalink
fix: Fix more JEI support
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jul 2, 2024
1 parent 11cb0d7 commit 6bd2a3a
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -309,7 +310,32 @@ public List<CompressedHammerRecipe> getCompressedHammerRecipes() {

@Override
public List<SieveRecipe> getSieveRecipes() {
return List.of();
List<SieveRecipe> result = new ArrayList<>();

final var recipeManager = ExCompressum.proxy.get().getRecipeManager(null);
ArrayListMultimap<Pair<IntList, CommonMeshType>, 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ItemStack> meshItems;
private final List<MergedLootTableEntry> outputs;
private final List<ItemStack> 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<LootTableEntry> 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<ItemStack> getMeshItems() {
return meshItems;
}

public List<MergedLootTableEntry> getOutputs() {
return outputs;
}

public List<ItemStack> getOutputItems() {
return outputItems;
}

public boolean isWaterlogged() {
return waterlogged;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public void registerRecipes(IRecipeRegistration registry) {

registry.addRecipes(HeavySieveJeiRecipeCategory.TYPE, expandedHeavySieveRecipes);

final var expandedSieveRecipes = new ArrayList<ExpandedSieveRecipe>();
for (final var recipe : ExNihilo.getInstance().getSieveRecipes()) {
expandedSieveRecipes.add(new ExpandedSieveRecipe(recipe));
}
registry.addRecipes(SieveJeiRecipeCategory.TYPE, expandedSieveRecipes);

List<ExpandedCompressedHammerRecipe> expandedCompressedHammerRecipes = new ArrayList<>();
final var compressedHammerRecipes = recipeManager.getAllRecipesFor(ModRecipeTypes.compressedHammerRecipeType);
for (final var recipe : compressedHammerRecipes) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ExpandedSieveRecipe> {

public static final ResourceLocation UID = new ResourceLocation(ExCompressum.MOD_ID, "sieve");
public static final RecipeType<ExpandedSieveRecipe> 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<ExpandedSieveRecipe> 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));
}
}

}
Original file line number Diff line number Diff line change
@@ -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<CommonMeshType> meshes;

public SieveRecipeImpl(ResourceLocation id, Ingredient ingredient, LootTable lootTable, boolean waterlogged, @Nullable CommonMeshType minimumMesh, @Nullable Set<CommonMeshType> 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<CommonMeshType> 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<CommonMeshType> meshes) {
this.meshes = meshes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 6bd2a3a

Please sign in to comment.