Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EMI support #50

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ repositories {
maven { url 'https://jitpack.io' } // Required for Dawn API

maven { url 'https://maven.shedaniel.me/' } // Required for Cloth Config and Roughly Enough Items
maven { url 'https://maven.terraformersmc.com/' } // Required for Mod Menu
maven { url 'https://maven.terraformersmc.com/' } // Required for Mod Menu and EMI
maven { url 'https://maven.ryanliptak.com/' } // Required for AppleSkin
}

dependencies {
modApi "com.github.DawnTeamMC:DawnAPI:${dawn_version}"

modApi "me.shedaniel:RoughlyEnoughItems-fabric:${rei_version}"
modCompileOnly "dev.emi:emi-fabric:${emi_version}:api"
modLocalRuntime "dev.emi:emi-fabric:${emi_version}"

compileOnly "com.google.code.findbugs:jsr305:3.0.2"
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ fabric_version=0.84.0+1.20.1
# https://github.com/DawnTeamMC/DawnAPI
dawn_version=5.0.0
# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=12.0.625
rei_version=12.0.625
# https://maven.terraformersmc.com/releases/dev/emi/emi-fabric/
emi_version=1.0.5+1.20.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.hugman.culinaire.compat.emi;

import com.hugman.culinaire.screen.handler.KettleScreenHandler;
import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.handler.StandardRecipeHandler;
import net.minecraft.screen.slot.Slot;

import java.util.List;

public class BrewingRecipeHandler implements StandardRecipeHandler<KettleScreenHandler> {
@Override
public List<Slot> getInputSources(KettleScreenHandler handler) {
return handler.slots;
}

@Override
public List<Slot> getCraftingSlots(KettleScreenHandler handler) {
return List.of(handler.getSlot(0));
}

@Override
public boolean supportsRecipe(EmiRecipe recipe) {
return CulinaireEMIPlugin.TEA_BREWING_CATEGORY.equals(recipe.getCategory());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.hugman.culinaire.compat.emi;

import com.hugman.culinaire.Culinaire;
import com.hugman.culinaire.recipe.TeaBagMakingRecipe;
import com.hugman.culinaire.registry.content.TeaContent;
import com.hugman.culinaire.tea.TeaHelper;
import com.hugman.culinaire.tea.TeaType;
import dev.emi.emi.api.EmiPlugin;
import dev.emi.emi.api.EmiRegistry;
import dev.emi.emi.api.recipe.EmiCraftingRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.stack.Comparison;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;

public class CulinaireEMIPlugin implements EmiPlugin {
public static final EmiRecipeCategory TEA_BREWING_CATEGORY =
new EmiRecipeCategory(Culinaire.id("plugins/tea_brewing"), EmiStack.of(TeaContent.KETTLE)) {
@Override
public Text getName() {
return Text.translatable("rei_category.culinaire.tea_brewing");
}
};

@Override
public void register(EmiRegistry registry) {
registry.addCategory(TEA_BREWING_CATEGORY);
registry.addWorkstation(TEA_BREWING_CATEGORY, EmiStack.of(TeaContent.KETTLE));

registerTeaBagDisplays(registry);
registerTeaBottleDisplays(registry);

registry.setDefaultComparison(EmiStack.of(TeaContent.TEA_BAG), Comparison.compareNbt());
registry.setDefaultComparison(EmiStack.of(TeaContent.TEA_BOTTLE), Comparison.compareNbt());

registry.addRecipeHandler(TeaContent.KETTLE_SCREEN_HANDLER, new BrewingRecipeHandler());
}

private void registerTeaBagDisplays(EmiRegistry registry) {
for (TeaType teaType : TeaHelper.getAllTypes()) {
DefaultedList<EmiIngredient> inputs = DefaultedList.of();
inputs.add(EmiIngredient.of(TeaBagMakingRecipe.PAPER));
inputs.add(EmiIngredient.of(TeaBagMakingRecipe.STRING));
EmiIngredient ingredient = EmiIngredient.of(teaType.getTag());
EmiStack output = EmiStack.of(TeaHelper.appendTeaType(new ItemStack(TeaContent.TEA_BAG), teaType));
if (!ingredient.isEmpty()) {
inputs.add(ingredient);
Identifier id = Culinaire.id(teaType.getStrength().getName() + "_" + teaType.getFlavor().getName() + "_tea_bag");
registry.addRecipe(new EmiCraftingRecipe(inputs, output, id, true));
}
registry.addEmiStack(output);
}
}

private void registerTeaBottleDisplays(EmiRegistry registry) {
for (TeaType teaType : TeaHelper.getAllTypes()) {
EmiIngredient input = EmiStack.of(TeaHelper.appendTeaType(new ItemStack(TeaContent.TEA_BAG), teaType));
EmiStack output = EmiStack.of(TeaHelper.appendTeaType(new ItemStack(TeaContent.TEA_BOTTLE), teaType));
Identifier id = Culinaire.id(teaType.getStrength().getName() + "_" + teaType.getFlavor().getName() + "_tea");
registry.addRecipe(new TeaBrewingEmiRecipe(input, output, id, teaType.getFlavor().getColor()));
registry.addEmiStack(output);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.hugman.culinaire.compat.emi;

import com.hugman.culinaire.Culinaire;
import com.mojang.blaze3d.systems.RenderSystem;
import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class TeaBrewingEmiRecipe implements EmiRecipe {
private static final Identifier DISPLAY_TEXTURE = Culinaire.id("textures/gui/rei/display.png");

private final EmiIngredient input;
private final EmiStack output;
private final int teaColor;
private final Identifier id;

public TeaBrewingEmiRecipe(EmiIngredient input, EmiStack output, Identifier id, int teaColor) {
this.input = input;
this.output = output;
this.id = id;
this.teaColor = teaColor;
}

@Override
public EmiRecipeCategory getCategory() {
return CulinaireEMIPlugin.TEA_BREWING_CATEGORY;
}

@Override
public @Nullable Identifier getId() {
return id;
}

@Override
public List<EmiIngredient> getInputs() {
return List.of(input);
}

@Override
public List<EmiStack> getOutputs() {
return List.of(output);
}

@Override
public int getDisplayWidth() {
return 70;
}

@Override
public int getDisplayHeight() {
return 61;
}

@Override
public void addWidgets(WidgetHolder widgets) {
widgets.addDrawable(0, 0, 70, 60, (gui, mouseX, mouseY, delta) -> {
// main texture
gui.drawTexture(DISPLAY_TEXTURE, 0, 0, 0, 0, 70, 60);

// tea color texture
float red = (teaColor >> 16 & 255) / 255.0F;
float green = (teaColor >> 8 & 255) / 255.0F;
float blue = (teaColor & 255) / 255.0F;
RenderSystem.setShaderColor(red, green, blue, 1.0F);
gui.drawTexture(DISPLAY_TEXTURE, 1, 32, 70, 0, 46, 16);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

// fire texture
gui.drawTexture(DISPLAY_TEXTURE, 12, 52, 70, 16, 24, 9);

// animated arrow texture
int height = MathHelper.ceil(System.currentTimeMillis() / 250d % 26d);
gui.drawTexture(DISPLAY_TEXTURE, 35, 1, 70, 25, 7, height);
});
widgets.addSlot(input, 15, 0).drawBack(false);
widgets.addSlot(output, 52, 31).drawBack(false).recipeContext(this);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
],
"rei_client": [
"com.hugman.culinaire.compat.rei.CulinaireREIPlugin"
],
"emi": [
"com.hugman.culinaire.compat.emi.CulinaireEMIPlugin"
]
},
"mixins": [
Expand Down