Skip to content

Commit

Permalink
EMI Compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Starexify committed Dec 21, 2024
1 parent 5970dd7 commit 31fffad
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 30 deletions.
24 changes: 8 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ version = mod_version
group = mod_group_id

repositories {
maven {
name = "TerraformersMC"
url = "https://maven.terraformersmc.com/"
}
mavenLocal()
}

Expand Down Expand Up @@ -104,21 +108,8 @@ dependencies {
// compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}"
// We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it
// localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}"

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation "blank:coolmod-${mc_version}:${coolmod_version}"

// Example mod dependency using a file as dependency
// implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar")

// Example project dependency using a sister or child project:
// implementation project(":myproject")

// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
compileOnly "dev.emi:emi-neoforge:${emi_version}+${minecraft_version}:api"
localRuntime "dev.emi:emi-neoforge:${emi_version}+${minecraft_version}"
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand All @@ -137,7 +128,8 @@ tasks.withType(ProcessResources).configureEach {
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description
mod_description : mod_description,
emi_version : emi_version
]
inputs.properties replaceProperties

Expand Down
14 changes: 9 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ org.gradle.daemon=false
org.gradle.debug=false

# Parchment
neogradle.subsystems.parchment.minecraftVersion=1.21
neogradle.subsystems.parchment.mappingsVersion=2024.11.10
neogradle.subsystems.parchment.minecraftVersion=1.21.1
neogradle.subsystems.parchment.mappingsVersion=2024.11.17

# Environment Properties

minecraft_version=1.21.1
minecraft_version_range=[1.21,1.21.1)

neo_version=21.1.82
neo_version_range=[21.0.0-beta
neo_version=21.1.90
neo_version_range=[21.0.0-beta,)
loader_version_range=[4,)

## Mod Properties
# Mod Properties

mod_id=nmt
mod_name=No More Things
Expand All @@ -25,3 +25,7 @@ mod_version=1.1.0
mod_group_id=net.nova.nmt
mod_authors=ImVeryBad, Foxirion
mod_description=This mod adds some THINGS

# Mod Integrations

emi_version=1.1.18
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pluginManagement {

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}
}
1 change: 1 addition & 0 deletions src/generated/resources/assets/nmt/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"block.nmt.obsidian_glass_pane": "Obsidian Glass Pane",
"container.ender_brewing": "Ender Brewing Stand",
"effect.nmt.burn": "Burn",
"emi.category.nmt.ender_brewing": "Ender Brewing",
"item.nmt.blazing_wither_soul": "Blazing Wither Soul",
"item.nmt.ender_wart": "Ender Wart",
"item.nmt.heart_of_the_hell": "Heart of the Hell",
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/net/nova/nmt/compat/emi/EmiEnderBrewingRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package net.nova.nmt.compat.emi;

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.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.nova.nmt.NoMoreThings;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class EmiEnderBrewingRecipe implements EmiRecipe {
private static final ResourceLocation BACKGROUND = NoMoreThings.rl("textures/gui/container/ender_brewing_stand.png");
private static final EmiStack WIND_CHARGE = EmiStack.of(Items.WIND_CHARGE);
private final EmiIngredient input, ingredient;
private final EmiStack output, input3, output3;
private final ResourceLocation id;

public EmiEnderBrewingRecipe(EmiStack input, EmiIngredient ingredient, EmiStack output, ResourceLocation id) {
this.input = input;
this.ingredient = ingredient;
this.output = output;
this.input3 = input.copy().setAmount(3);
this.output3 = output.copy().setAmount(3);
this.id = id;
}

@Override
public EmiRecipeCategory getCategory() {
return NMTEmi.ENDER_BREWING;
}

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

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

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

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

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

@Override
public void addWidgets(WidgetHolder widgets) {
widgets.addTexture(BACKGROUND, 0, 0, 103, 61, 16, 14);
widgets.addAnimatedTexture(BACKGROUND, 81, 2, 9, 28, 176, 0, 1000 * 20, false, false, false).tooltip((mx, my) -> {
return List.of(ClientTooltipComponent.create(Component.translatable("emi.cooking.time", 20).getVisualOrderText()));

});
widgets.addAnimatedTexture(BACKGROUND, 47, 0, 12, 29, 185, 0, 700, false, true, false);
widgets.addTexture(BACKGROUND, 44, 30, 18, 4, 176, 29);
widgets.addSlot(WIND_CHARGE, 0, 2).drawBack(false);
widgets.addSlot(input, 39, 36).drawBack(false);
widgets.addSlot(ingredient, 62, 2).drawBack(false);
widgets.addSlot(output, 85, 36).drawBack(false).recipeContext(this);
}
}
158 changes: 158 additions & 0 deletions src/main/java/net/nova/nmt/compat/emi/NMTEmi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package net.nova.nmt.compat.emi;

import dev.emi.emi.api.EmiEntrypoint;
import dev.emi.emi.api.EmiPlugin;
import dev.emi.emi.api.EmiRegistry;
import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.recipe.EmiRecipeSorting;
import dev.emi.emi.api.recipe.EmiWorldInteractionRecipe;
import dev.emi.emi.api.render.EmiRenderable;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.PotionItem;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Fluids;
import net.neoforged.neoforge.common.brewing.BrewingRecipe;
import net.neoforged.neoforge.common.brewing.IBrewingRecipe;
import net.nova.nmt.NoMoreThings;
import net.nova.nmt.init.NMTBlocks;
import net.nova.nmt.init.NMTItems;
import net.nova.nmt.init.NMTPotions;
import net.nova.nmt.recipe.EnderPotionBrewing;

import java.util.function.Consumer;
import java.util.function.Supplier;

import static dev.emi.emi.api.recipe.VanillaEmiRecipeCategories.*;
import static dev.emi.emi.api.recipe.VanillaEmiRecipeCategories.INFO;
import static net.nova.nmt.NoMoreThings.MODID;

@EmiEntrypoint
public class NMTEmi implements EmiPlugin {
public static final EmiRecipeCategory ENDER_BREWING = new EmiRecipeCategory(NoMoreThings.rl("ender_brewing"), EmiStack.of(NMTBlocks.ENDER_BREWING_STAND),
new EmiTexture(NoMoreThings.rl("textures/gui/emi_simplified_textures.png"), 0, 0, 16, 16));

@Override
public void register(EmiRegistry registry) {
registry.addCategory(ENDER_BREWING);
registry.addWorkstation(ENDER_BREWING, EmiStack.of(NMTBlocks.ENDER_BREWING_STAND));

addEnderRecipes(registry);
addWorldInteraction(registry);
}

public void addEnderRecipes(EmiRegistry registry) {
EnderPotionBrewing enderBrewing = Minecraft.getInstance().level != null ? NoMoreThings.getEnderBrewing() : EnderPotionBrewing.EMPTY;
for (Ingredient ingredient : enderBrewing.containers) {
for (ItemStack stack : ingredient.getItems()) {
String pid = subId(stack.getItem());
for (EnderPotionBrewing.Mix<Potion> recipe : enderBrewing.potionMixes) {
try {
if (recipe.ingredient().getItems().length > 0) {
ResourceLocation id = NoMoreThings.rl("/ender_brewing/" + pid
+ "/" + subId(recipe.ingredient().getItems()[0].getItem())
+ "/" + subId(BuiltInRegistries.POTION.getKey(recipe.from().value()))
+ "/" + subId(BuiltInRegistries.POTION.getKey(recipe.to().value())));
registry.addRecipe(new EmiEnderBrewingRecipe(
EmiStack.of(setPotion(stack.copy(), recipe.from().value())), EmiIngredient.of(recipe.ingredient()),
EmiStack.of(setPotion(stack.copy(), recipe.to().value())), id));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

for (EnderPotionBrewing.Mix<Item> recipe : enderBrewing.containerMixes) {
try {
if (recipe.ingredient().getItems().length > 0) {
String gid = subId(recipe.ingredient().getItems()[0].getItem());
String iid = subId(recipe.from().value());
String oid = subId(recipe.to().value());
Consumer<Holder<Potion>> potionRecipeGen = entry -> {
Potion potion = entry.value();
if (enderBrewing.isBrewablePotion(entry)) {
ResourceLocation id = NoMoreThings.rl("/ender_brewing/item/"
+ subId(entry.unwrapKey().get().location()) + "/" + gid + "/" + iid + "/" + oid);
registry.addRecipe(new EmiEnderBrewingRecipe(
EmiStack.of(setPotion(new ItemStack(recipe.from().value()), potion)), EmiIngredient.of(recipe.ingredient()),
EmiStack.of(setPotion(new ItemStack(recipe.to().value()), potion)), id));
}
};
if ((recipe.from().value() instanceof PotionItem)) {
BuiltInRegistries.POTION.holders().forEach(potionRecipeGen);
} else {
potionRecipeGen.accept(Potions.AWKWARD);
}

}
} catch (Exception e) {
e.printStackTrace();
}
}
}

public static void addWorldInteraction(EmiRegistry registry) {
EmiStack lava = EmiStack.of(Fluids.LAVA, 1000);

addRecipeSafe(registry, () -> basicWorld(EmiStack.of(NMTItems.OBSIDIAN_GLASS_BOTTLE), lava,
EmiStack.of(setPotion(new ItemStack(NMTItems.OBSIDIAN_POTION.get()), NMTPotions.LAVA.value())),
synthetic("world/unique", "nmt/lava_bottle")));

EmiStack lavaBottle = EmiStack.of(setPotion(new ItemStack(NMTItems.OBSIDIAN_POTION.get()), NMTPotions.LAVA.value()))
.setRemainder(EmiStack.of(NMTItems.OBSIDIAN_GLASS_BOTTLE));
EmiStack magma_block = EmiStack.of(Items.MAGMA_BLOCK);
addRecipeSafe(registry, () -> basicWorld(EmiStack.of(Items.NETHERRACK), lavaBottle, magma_block, synthetic("world/unique", "minecraft/magma_block"), false));
}

public static String subId(ResourceLocation id) {
return id.getNamespace() + "/" + id.getPath();
}

public static String subId(Item item) {
return subId(BuiltInRegistries.ITEM.getKey(item));
}

public static ItemStack setPotion(ItemStack stack, Potion potion) {
stack.update(DataComponents.POTION_CONTENTS, PotionContents.EMPTY, BuiltInRegistries.POTION.wrapAsHolder(potion), PotionContents::withPotion);
return stack;
}

public static ResourceLocation synthetic(String type, String name) {
return NoMoreThings.rl("/" + type + "/" + name);
}

public static void addRecipeSafe(EmiRegistry registry, Supplier<EmiRecipe> supplier) {
registry.addRecipe(supplier.get());
}

public static EmiRecipe basicWorld(EmiIngredient left, EmiIngredient right, EmiStack output, ResourceLocation id) {
return basicWorld(left, right, output, id, true);
}

public static EmiRecipe basicWorld(EmiIngredient left, EmiIngredient right, EmiStack output, ResourceLocation id, boolean catalyst) {
return EmiWorldInteractionRecipe.builder()
.id(id)
.leftInput(left)
.rightInput(right, catalyst)
.output(output)
.build();
}
}
3 changes: 3 additions & 0 deletions src/main/java/net/nova/nmt/data/LangProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ protected void addTranslations() {

// Block Entity
add("container.ender_brewing", "Ender Brewing Stand");

// EMI
add("emi.category.nmt.ender_brewing", "Ender Brewing");
}

public void addObsidianPotion(Supplier<? extends Item> key, Holder<Potion> potionName, String name) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/nova/nmt/init/NMTEntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class NMTEntityType {
.build("obsidian_potion")
);

public static final Supplier<EntityType<FireballProjectile>> FIREBALL_PROJECTILE = ENTITY_TYPES.register("fireball_projectile",
/* public static final Supplier<EntityType<FireballProjectile>> FIREBALL_PROJECTILE = ENTITY_TYPES.register("fireball_projectile",
() -> EntityType.Builder.<FireballProjectile>of(FireballProjectile::new, MobCategory.MISC)
.sized(0.25F, 0.25F)
.clientTrackingRange(4)
.updateInterval(10)
.build("fireball_projectile")
);
);*/

}
Loading

0 comments on commit 31fffad

Please sign in to comment.