Skip to content

Commit

Permalink
Merge pull request #140 from moonfather1/emi_support
Browse files Browse the repository at this point in the history
EMI support
  • Loading branch information
Alatyami authored Aug 19, 2024
2 parents 8e595ad + e55371c commit e391608
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 7 deletions.
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ dependencies {
compileOnly(fg.deobf("mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}"))
compileOnly fg.deobf("curse.maven:mekanism-${curseforge_mekanism}")
compileOnly fg.deobf("curse.maven:immersive-engineering-${curseforge_immersive_engineering}")
compileOnly fg.deobf("curse.maven:emi-580555:5497473")

// Runtime mods for testing
runtimeOnly fg.deobf("curse.maven:theoneprobe-${curseforge_theoneprobe}")
runtimeOnly fg.deobf("curse.maven:jei-${curseforge_jei}")
runtimeOnly fg.deobf("curse.maven:patchouli-${curseforge_patchouli}")
runtimeOnly fg.deobf("curse.maven:appleskin-${curseforge_appleskin}")
runtimeOnly fg.deobf("curse.maven:mekanism-${curseforge_mekanism}")
runtimeOnly fg.deobf("curse.maven:farmers-delight-${curseforge_farmers_delight}")
runtimeOnly fg.deobf("curse.maven:immersive-engineering-${curseforge_immersive_engineering}")
runtimeOnly fg.deobf("curse.maven:serene-seasons-${curseforge_serene_seasons}")
//runtimeOnly fg.deobf("curse.maven:serene-seasons-${curseforge_serene_seasons}")

// Runtime mods for testing, pick one
//runtimeOnly fg.deobf("curse.maven:jei-${curseforge_jei}")
runtimeOnly fg.deobf("curse.maven:emi-580555:5497473")

// Nice thing that shows the nbt in scrollable manner
runtimeOnly fg.deobf("curse.maven:item-nbt-viewer-514135:4578522")
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/growthcraft/cellar/compat/emi/EmiBarrelRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package growthcraft.cellar.compat.emi;

import dev.emi.emi.api.recipe.BasicEmiRecipe;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import growthcraft.cellar.recipe.FermentationBarrelRecipe;
import net.minecraft.world.item.crafting.Ingredient;

public class EmiBarrelRecipe extends BasicEmiRecipe
{
public EmiBarrelRecipe(FermentationBarrelRecipe recipe)
{
super(EmiPlugin.BARREL_RECIPE_CATEGORY, recipe.getId(), 125, 18);
this.inputs.add(EmiStack.of(recipe.getIngredientFluidStack().getFluid()));
this.inputs.add(EmiIngredient.of(Ingredient.of(recipe.getIngredientItemStack())));
this.outputs.add(EmiStack.of(recipe.getResultingFluid().getFluid().getBucket()));
this.outputs.add(EmiStack.of(recipe.getResultingFluid().getFluid()));
}

@Override
public void addWidgets(WidgetHolder widgetHolder)
{
// Add plus and arrow textures
widgetHolder.addTexture(EmiTexture.PLUS, 27, 3);
widgetHolder.addTexture(EmiTexture.EMPTY_ARROW, 75, 1);
// Adds an input slot 1
widgetHolder.addSlot(inputs.get(0), 0, 0);
// Adds an input slot 2
widgetHolder.addSlot(inputs.get(1), 49, 0);
// Adds an output slot on the right
// Note that output slots need to call `recipeContext` to inform EMI about their recipe context
// This includes being able to resolve recipe trees, favorite stacks with recipe context, and more
widgetHolder.addSlot(outputs.get(1), 107, 0).recipeContext(this);
}
}
52 changes: 52 additions & 0 deletions src/main/java/growthcraft/cellar/compat/emi/EmiFarmingRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package growthcraft.cellar.compat.emi;

import dev.emi.emi.api.recipe.BasicEmiRecipe;
import dev.emi.emi.api.recipe.VanillaEmiRecipeCategories;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import growthcraft.cellar.shared.Reference;
import growthcraft.core.init.GrowthcraftItems;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Blocks;

public class EmiFarmingRecipe extends BasicEmiRecipe
{
private static final ResourceLocation WIDGETS = new ResourceLocation("growthcraft:textures/gui/widgets.png");
private static final EmiTexture SMALL_PLUS = new EmiTexture(WIDGETS, 83, 1, 10, 10);
private static final EmiTexture SMALL_ARROW = new EmiTexture(WIDGETS, 44, 0, 20, 15);
private static final EmiIngredient SLOT0 = EmiIngredient.of(Ingredient.of(Blocks.FARMLAND));
private static final EmiIngredient SLOT2 = EmiIngredient.of(Ingredient.of(GrowthcraftItems.ROPE_LINEN.get()));
private static int counter = 1;
private final EmiIngredient SLOT1, SLOT3;

public EmiFarmingRecipe(ItemLike input, ItemLike output)
{
super(VanillaEmiRecipeCategories.WORLD_INTERACTION, new ResourceLocation(Reference.MODID, "f"+counter), 125, 18);
counter++;
SLOT1 = EmiIngredient.of(Ingredient.of(input));
SLOT3 = EmiIngredient.of(Ingredient.of(output));
this.inputs.add(SLOT1);
this.inputs.add(SLOT2);
this.outputs.add(EmiStack.of(output));
}

@Override
public void addWidgets(WidgetHolder widgetHolder)
{
widgetHolder.addSlot(SLOT0, 0, 0);
widgetHolder.addTexture(SMALL_PLUS, 20, 3);
widgetHolder.addSlot(SLOT1, 32, 0);
widgetHolder.addTexture(SMALL_PLUS, 52, 3);
widgetHolder.addSlot(SLOT2, 64, 0);
widgetHolder.addTexture(SMALL_ARROW, 83, 1);
// Adds an output slot on the right
// Note that output slots need to call `recipeContext` to inform EMI about their recipe context
// This includes being able to resolve recipe trees, favorite stacks with recipe context, and more
widgetHolder.addSlot(SLOT3, 106, 0).recipeContext(this);
}
}
33 changes: 33 additions & 0 deletions src/main/java/growthcraft/cellar/compat/emi/EmiJarRecipe1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package growthcraft.cellar.compat.emi;

import dev.emi.emi.api.recipe.BasicEmiRecipe;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import growthcraft.cellar.recipe.CultureJarRecipe;
import growthcraft.cellar.recipe.CultureJarStarterRecipe;
import net.minecraft.world.item.crafting.Ingredient;

public class EmiJarRecipe1 extends BasicEmiRecipe
{
public EmiJarRecipe1(CultureJarStarterRecipe recipe)
{
super(EmiPlugin.JAR_RECIPE_CATEGORY1, recipe.getId(), 125, 18);
this.inputs.add(EmiStack.of(recipe.getInputFluidStack().getFluid(), recipe.getInputFluidStack().getAmount()));
this.outputs.add(EmiStack.of(recipe.getInputItemStack()));
}

@Override
public void addWidgets(WidgetHolder widgetHolder)
{
// Add an arrow texture to indicate processing
widgetHolder.addTexture(EmiTexture.EMPTY_ARROW, 26, 1);
// Adds an input slot on the left
widgetHolder.addSlot(inputs.get(0), 0, 0);
// Adds an output slot on the right
// Note that output slots need to call `recipeContext` to inform EMI about their recipe context
// This includes being able to resolve recipe trees, favorite stacks with recipe context, and more
widgetHolder.addSlot(outputs.get(0), 58, 0).recipeContext(this);
}
}
37 changes: 37 additions & 0 deletions src/main/java/growthcraft/cellar/compat/emi/EmiJarRecipe2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package growthcraft.cellar.compat.emi;

import dev.emi.emi.api.recipe.BasicEmiRecipe;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import growthcraft.cellar.recipe.CultureJarRecipe;
import growthcraft.cellar.recipe.FermentationBarrelRecipe;
import net.minecraft.world.item.crafting.Ingredient;

public class EmiJarRecipe2 extends BasicEmiRecipe
{
public EmiJarRecipe2(CultureJarRecipe recipe)
{
super(EmiPlugin.JAR_RECIPE_CATEGORY2, recipe.getId(), 125, 18);
this.inputs.add(EmiStack.of(recipe.getInputFluidStack().getFluid(), recipe.getInputFluidStack().getAmount()));
this.inputs.add(EmiStack.of(recipe.getInputItemStack()));
this.outputs.add(EmiStack.of(recipe.getInputItemStack()));
}

@Override
public void addWidgets(WidgetHolder widgetHolder)
{
// Add plus and arrow textures
widgetHolder.addTexture(EmiTexture.PLUS, 27, 3);
widgetHolder.addTexture(EmiTexture.EMPTY_ARROW, 75, 1);
// Adds an input slot 1
widgetHolder.addSlot(inputs.get(0), 0, 0);
// Adds an input slot 2
widgetHolder.addSlot(inputs.get(1), 49, 0);
// Adds an output slot on the right
// Note that output slots need to call `recipeContext` to inform EMI about their recipe context
// This includes being able to resolve recipe trees, favorite stacks with recipe context, and more
widgetHolder.addSlot(outputs.get(0), 107, 0).recipeContext(this);
}
}
60 changes: 60 additions & 0 deletions src/main/java/growthcraft/cellar/compat/emi/EmiKettleRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package growthcraft.cellar.compat.emi;

import dev.emi.emi.api.recipe.BasicEmiRecipe;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import growthcraft.cellar.recipe.BrewKettleRecipe;
import growthcraft.cellar.recipe.FermentationBarrelRecipe;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Ingredient;

import java.util.List;

public class EmiKettleRecipe extends BasicEmiRecipe
{
private final boolean hasByproduct, isSteaming;
private final int chanceForByproduct;

public EmiKettleRecipe(BrewKettleRecipe recipe) {
super(EmiPlugin.KETTLE_RECIPE_CATEGORY, recipe.getId(), 125, 18);
this.inputs.add(EmiIngredient.of(recipe.getIngredients().isEmpty() ? Ingredient.EMPTY : recipe.getIngredients().get(0)));
this.inputs.add(EmiStack.of(recipe.getInputFluidStack().getFluid(), recipe.getInputFluidStack().getAmount()));
this.outputs.add(EmiStack.of(recipe.getOutputFluidStack().getFluid().getBucket()));
this.outputs.add(EmiStack.of(recipe.getOutputFluidStack().getFluid(),recipe.getOutputFluidStack().getAmount()));
this.outputs.add(EmiStack.of(recipe.getByProduct()));
this.hasByproduct = ! recipe.getByProduct().isEmpty() && recipe.getByProductChance() > 0;
this.chanceForByproduct = recipe.getByProductChance();
this.isSteaming = recipe.isLidRequired();
}

@Override
public void addWidgets(WidgetHolder widgetHolder) {
// Adds input slot 1
widgetHolder.addSlot(inputs.get(1), 0, 0);
// Add texture
widgetHolder.addTexture(SMALL_PLUS, 20, 3);
// Adds input slot 2
widgetHolder.addSlot(inputs.get(0), 32, 0);
// Add texture
widgetHolder.addTexture(SMALL_ARROW, 52, 1);
String key = this.isSteaming ? "message.growthcraft_cellar.kettle.jei_info_need_lid" : "message.growthcraft_cellar.kettle.jei_info_no_lid";
widgetHolder.addTooltipText(List.of(Component.translatable(key)), 50, 0, 24, 17);
// Adds an output slot on the right
// Note that output slots need to call `recipeContext` to inform EMI about their recipe context
// This includes being able to resolve recipe trees, favorite stacks with recipe context, and more
widgetHolder.addSlot(outputs.get(1), 74, 0).recipeContext(this);
if (this.hasByproduct) {
// Add texture
widgetHolder.addTexture(SMALL_PLUS, 94, 3);
// Adds output slot 2
widgetHolder.addSlot(outputs.get(2), 107, 0);
widgetHolder.addTooltipText(List.of(Component.literal("%d%%".formatted(this.chanceForByproduct))), 92, 1, 14, 14);
}
}
private static final ResourceLocation WIDGETS = new ResourceLocation("growthcraft:textures/gui/widgets.png");
private static final EmiTexture SMALL_PLUS = new EmiTexture(WIDGETS, 83, 1, 10, 10);
private static final EmiTexture SMALL_ARROW = new EmiTexture(WIDGETS, 44, 0, 20, 15);
}
Loading

0 comments on commit e391608

Please sign in to comment.