From dccb839d32e66c09b5acd990bfa609e216792475 Mon Sep 17 00:00:00 2001 From: Abbie Date: Sun, 7 May 2023 16:49:28 +0100 Subject: [PATCH 1/2] Add EMI support --- build.gradle | 3 +- gradle.properties | 3 +- .../compat/emi/BrewingRecipeHandler.java | 25 ++++++ .../compat/emi/CulinaireEMIPlugin.java | 71 +++++++++++++++ .../compat/emi/TeaBrewingEmiRecipe.java | 88 +++++++++++++++++++ src/main/resources/fabric.mod.json | 3 + 6 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/hugman/culinaire/compat/emi/BrewingRecipeHandler.java create mode 100644 src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java create mode 100644 src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java diff --git a/build.gradle b/build.gradle index 5ea4978..a180d3a 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ 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 } @@ -18,6 +18,7 @@ dependencies { modApi "com.github.DawnTeamMC:DawnAPI:v${dawn_version}" modApi "me.shedaniel:RoughlyEnoughItems-fabric:${rei_version}" + modApi "dev.emi:emi:${emi_version}" compileOnly "com.google.code.findbugs:jsr305:3.0.2" } diff --git a/gradle.properties b/gradle.properties index d369380..9fc78ff 100644 --- a/gradle.properties +++ b/gradle.properties @@ -38,4 +38,5 @@ fabric_version=0.76.0+1.19.4 # https://github.com/DawnTeamMC/DawnAPI dawn_version=4-SNAPSHOT # https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/ -rei_version=11.0.597 \ No newline at end of file +rei_version=11.0.597 +emi_version=0.7.3+1.19.4 \ No newline at end of file diff --git a/src/main/java/com/hugman/culinaire/compat/emi/BrewingRecipeHandler.java b/src/main/java/com/hugman/culinaire/compat/emi/BrewingRecipeHandler.java new file mode 100644 index 0000000..d3436d8 --- /dev/null +++ b/src/main/java/com/hugman/culinaire/compat/emi/BrewingRecipeHandler.java @@ -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 { + @Override + public List getInputSources(KettleScreenHandler handler) { + return handler.slots; + } + + @Override + public List getCraftingSlots(KettleScreenHandler handler) { + return List.of(handler.getSlot(0)); + } + + @Override + public boolean supportsRecipe(EmiRecipe recipe) { + return CulinaireEMIPlugin.TEA_BREWING_CATEGORY.equals(recipe.getCategory()); + } +} diff --git a/src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java b/src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java new file mode 100644 index 0000000..6715261 --- /dev/null +++ b/src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java @@ -0,0 +1,71 @@ +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; + +import java.util.function.Function; + +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); + + Function compareNbt = c -> c.copy().nbt(true).build(); + registry.setDefaultComparison(EmiStack.of(TeaContent.TEA_BAG), compareNbt); + registry.setDefaultComparison(EmiStack.of(TeaContent.TEA_BOTTLE), compareNbt); + + registry.addRecipeHandler(TeaContent.KETTLE_SCREEN_HANDLER, new BrewingRecipeHandler()); + } + + private void registerTeaBagDisplays(EmiRegistry registry) { + for (TeaType teaType : TeaHelper.getAllTypes()) { + DefaultedList 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); + } + } +} diff --git a/src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java b/src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java new file mode 100644 index 0000000..021cf53 --- /dev/null +++ b/src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java @@ -0,0 +1,88 @@ +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.client.gui.DrawableHelper; +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 getInputs() { + return List.of(input); + } + + @Override + public List 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, (matrices, mouseX, mouseY, delta) -> { + RenderSystem.setShaderTexture(0, DISPLAY_TEXTURE); + + // main texture + DrawableHelper.drawTexture(matrices, 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); + DrawableHelper.drawTexture(matrices, 1, 32, 70, 0, 46, 16); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + + // fire texture + DrawableHelper.drawTexture(matrices, 12, 52, 70, 16, 24, 9); + + // animated arrow texture + int height = MathHelper.ceil(System.currentTimeMillis() / 250d % 26d); + DrawableHelper.drawTexture(matrices, 35, 1, 70, 25, 7, height); + }); + widgets.addSlot(input, 15, 0).drawBack(false); + widgets.addSlot(output, 52, 31).drawBack(false).recipeContext(this); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 28bc333..6f81110 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -31,6 +31,9 @@ ], "rei_client": [ "com.hugman.culinaire.compat.rei.CulinaireREIPlugin" + ], + "emi": [ + "com.hugman.culinaire.compat.emi.CulinaireEMIPlugin" ] }, "mixins": [ From a3b502a760da5325e0995d18f553622464da8e58 Mon Sep 17 00:00:00 2001 From: Abbie Date: Thu, 6 Jul 2023 11:16:47 +0100 Subject: [PATCH 2/2] update emi dep --- build.gradle | 3 ++- gradle.properties | 3 ++- .../culinaire/compat/emi/CulinaireEMIPlugin.java | 7 ++----- .../culinaire/compat/emi/TeaBrewingEmiRecipe.java | 13 +++++-------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 013ba99..c239f04 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,8 @@ dependencies { modApi "com.github.DawnTeamMC:DawnAPI:${dawn_version}" modApi "me.shedaniel:RoughlyEnoughItems-fabric:${rei_version}" - modApi "dev.emi:emi:${emi_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" } diff --git a/gradle.properties b/gradle.properties index 25a20b3..8efeb19 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,5 @@ fabric_version=0.84.0+1.20.1 dawn_version=5.0.0 # https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/ rei_version=12.0.625 -emi_version=0.7.3+1.19.4 \ No newline at end of file +# https://maven.terraformersmc.com/releases/dev/emi/emi-fabric/ +emi_version=1.0.5+1.20.1 \ No newline at end of file diff --git a/src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java b/src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java index 6715261..5442012 100644 --- a/src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java +++ b/src/main/java/com/hugman/culinaire/compat/emi/CulinaireEMIPlugin.java @@ -17,8 +17,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; -import java.util.function.Function; - public class CulinaireEMIPlugin implements EmiPlugin { public static final EmiRecipeCategory TEA_BREWING_CATEGORY = new EmiRecipeCategory(Culinaire.id("plugins/tea_brewing"), EmiStack.of(TeaContent.KETTLE)) { @@ -36,9 +34,8 @@ public void register(EmiRegistry registry) { registerTeaBagDisplays(registry); registerTeaBottleDisplays(registry); - Function compareNbt = c -> c.copy().nbt(true).build(); - registry.setDefaultComparison(EmiStack.of(TeaContent.TEA_BAG), compareNbt); - registry.setDefaultComparison(EmiStack.of(TeaContent.TEA_BOTTLE), compareNbt); + 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()); } diff --git a/src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java b/src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java index 021cf53..72eddd5 100644 --- a/src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java +++ b/src/main/java/com/hugman/culinaire/compat/emi/TeaBrewingEmiRecipe.java @@ -7,7 +7,6 @@ import dev.emi.emi.api.stack.EmiIngredient; import dev.emi.emi.api.stack.EmiStack; import dev.emi.emi.api.widget.WidgetHolder; -import net.minecraft.client.gui.DrawableHelper; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; @@ -61,26 +60,24 @@ public int getDisplayHeight() { @Override public void addWidgets(WidgetHolder widgets) { - widgets.addDrawable(0, 0, 70, 60, (matrices, mouseX, mouseY, delta) -> { - RenderSystem.setShaderTexture(0, DISPLAY_TEXTURE); - + widgets.addDrawable(0, 0, 70, 60, (gui, mouseX, mouseY, delta) -> { // main texture - DrawableHelper.drawTexture(matrices, 0, 0, 0, 0, 70, 60); + 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); - DrawableHelper.drawTexture(matrices, 1, 32, 70, 0, 46, 16); + gui.drawTexture(DISPLAY_TEXTURE, 1, 32, 70, 0, 46, 16); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); // fire texture - DrawableHelper.drawTexture(matrices, 12, 52, 70, 16, 24, 9); + gui.drawTexture(DISPLAY_TEXTURE, 12, 52, 70, 16, 24, 9); // animated arrow texture int height = MathHelper.ceil(System.currentTimeMillis() / 250d % 26d); - DrawableHelper.drawTexture(matrices, 35, 1, 70, 25, 7, height); + 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);