Skip to content

Commit

Permalink
Add in JEI category
Browse files Browse the repository at this point in the history
  • Loading branch information
voidsong-dragonfly committed Mar 18, 2024
1 parent acb880f commit 442b272
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
package blusunrize.immersiveengineering.common.util.compat.jei.cloche;

import blusunrize.immersiveengineering.api.crafting.ClocheFertilizer;
import blusunrize.immersiveengineering.client.ClientUtils;
import blusunrize.immersiveengineering.common.register.IEBlocks;
import blusunrize.immersiveengineering.common.util.Utils;
import blusunrize.immersiveengineering.common.util.compat.jei.IERecipeCategory;
import blusunrize.immersiveengineering.common.util.compat.jei.JEIHelper;
import blusunrize.immersiveengineering.common.util.compat.jei.JEIRecipeTypes;
Expand All @@ -19,21 +21,22 @@
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.world.item.ItemStack;

public class ClocheFertilizerCategory extends IERecipeCategory<ClocheFertilizer>
{
public ClocheFertilizerCategory(IGuiHelper helper)
{
super(helper, JEIRecipeTypes.CLOCHE_FERTILIZER, "ie.jei.category.fertilizer");
setBackground(helper.createBlankDrawable(100, 50));
super(helper, JEIRecipeTypes.CLOCHE_FERTILIZER, "desc.immersiveengineering.jei.category.fertilizer");
setBackground(helper.createBlankDrawable(150, 50));
setIcon(new ItemStack(IEBlocks.MetalDevices.CLOCHE));
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, ClocheFertilizer recipe, IFocusGroup focuses)
{
builder.addSlot(RecipeIngredientRole.INPUT, 35, 13)
builder.addSlot(RecipeIngredientRole.INPUT, 33, 13)
.addItemStack(recipe.input.getItems()[0])
.setBackground(JEIHelper.slotDrawable, -1, -1);
}
Expand All @@ -43,7 +46,9 @@ public void draw(ClocheFertilizer recipe, IRecipeSlotsView recipeSlotsView, GuiG
{
graphics.pose().pushPose();
graphics.pose().scale(3, 3, 1);
this.getIcon().draw(graphics, -1, 0);
this.getIcon().draw(graphics, -2, 0);
graphics.pose().popPose();
String growthModifier = I18n.get("desc.immersiveengineering.jei.cloche_modifier", Utils.formatDouble(recipe.growthModifier, "#.##"));
graphics.drawString(ClientUtils.font(), growthModifier, 53, 17, 0x777777, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,82 @@

package blusunrize.immersiveengineering.common.util.compat.jei.cloche;

import blusunrize.immersiveengineering.api.Lib;
import blusunrize.immersiveengineering.api.crafting.ClocheFertilizer;
import blusunrize.immersiveengineering.api.crafting.ClocheRecipe;
import blusunrize.immersiveengineering.common.register.IEBlocks;
import blusunrize.immersiveengineering.common.util.compat.jei.IERecipeCategory;
import blusunrize.immersiveengineering.common.util.compat.jei.JEIHelper;
import blusunrize.immersiveengineering.common.util.compat.jei.JEIRecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.forge.ForgeTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.material.Fluids;
import net.minecraftforge.fluids.FluidStack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Collectors;

public class ClocheRecipeCategory extends IERecipeCategory<ClocheRecipe>
{
private final IDrawableStatic tankOverlay;
private final IDrawableAnimated arrow;

public ClocheRecipeCategory(IGuiHelper helper)
{
super(helper, JEIRecipeTypes.CLOCHE, "block.immersiveengineering.cloche");
setBackground(helper.createBlankDrawable(100, 50));
ResourceLocation background = new ResourceLocation(Lib.MODID, "textures/gui/cloche.png");
setBackground(helper.createDrawable(background, 0, 0, 176, 77));
setIcon(new ItemStack(IEBlocks.MetalDevices.CLOCHE));
tankOverlay = helper.createDrawable(background, 176, 30, 20, 51);
arrow = helper.drawableBuilder(background, 181, 1, 13, 13).buildAnimated(200, IDrawableAnimated.StartDirection.LEFT, false);
}

@Override
public void setRecipe(IRecipeLayoutBuilder builder, ClocheRecipe recipe, IFocusGroup focuses)
{
builder.addSlot(RecipeIngredientRole.INPUT, 5, 7)
.addItemStacks(Arrays.asList(recipe.seed.getItems()))
.setBackground(JEIHelper.slotDrawable, -1, -1);
builder.addSlot(RecipeIngredientRole.INPUT, 62, 34)
.addItemStacks(Arrays.asList(recipe.seed.getItems()));

builder.addSlot(RecipeIngredientRole.INPUT, 5, 31)
.addItemStacks(Arrays.asList(recipe.soil.getItems()))
.setBackground(JEIHelper.slotDrawable, -1, -1);
builder.addSlot(RecipeIngredientRole.INPUT, 62, 54)
.addItemStacks(Arrays.asList(recipe.soil.getItems()));

for(int i = 0; i < recipe.outputs.size(); i++)
builder.addSlot(RecipeIngredientRole.OUTPUT, 65+i%2*18, 13+i/2*18)
.addItemStack(recipe.outputs.get(i).get())
.setBackground(JEIHelper.slotDrawable, -1, -1);
builder.addSlot(RecipeIngredientRole.OUTPUT, 116+i%2*18, 34+i/2*18)
.addItemStack(recipe.outputs.get(i).get());

builder.addSlot(RecipeIngredientRole.INPUT, 6, 6)
.setFluidRenderer(4000, false, 20, 51)
.setOverlay(tankOverlay, 0, 0)
.addIngredient(ForgeTypes.FLUID_STACK, new FluidStack(Fluids.WATER, 4000))
.addTooltipCallback(JEIHelper.fluidTooltipCallback);

// TODO: Fix this to not be this unperformant and just bad, if there is a better way to do it
ArrayList<ItemStack> fertilizers = new ArrayList<>(Collections.singleton(ItemStack.EMPTY));
for(ClocheFertilizer fertilizerList : ClocheFertilizer.RECIPES.getRecipes(Minecraft.getInstance().level))
fertilizers.addAll(Arrays.stream(fertilizerList.input.getItems()).toList());

builder.addSlot(RecipeIngredientRole.INPUT, 8, 59)
.addItemStacks(fertilizers);
}

@Override
public void draw(ClocheRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics graphics, double mouseX, double mouseY)
{
graphics.pose().pushPose();
graphics.pose().scale(3, 3, 1);
this.getIcon().draw(graphics, 7, 0);
graphics.pose().popPose();
arrow.draw(graphics, 101, 35);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1402,5 +1402,6 @@
"config.jade.plugin_immersiveengineering.multiblock_icon": "Multiblock Icons",
"config.jade.plugin_immersiveengineering.multiblock_tank": "Multiblock Tank",
"config.jade.plugin_immersiveengineering.multiblock_inventory": "Multiblock Inventory",
"ie.jei.category.fertilizer": "Garden Cloche Fertilizer"
"desc.immersiveengineering.jei.category.fertilizer": "Garden Cloche Fertilizer",
"desc.immersiveengineering.jei.cloche_modifier": "Growth Modifier: %1$s"
}

0 comments on commit 442b272

Please sign in to comment.