Skip to content

Commit

Permalink
EMI Compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Starexify committed Dec 24, 2024
1 parent 86ebf0f commit 35139b5
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions src/main/java/net/nova/nmt/compat/emi/NMTEmi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
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.recipe.*;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
Expand All @@ -20,15 +17,17 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.material.Fluids;
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.item.ObsidianPotionItem;
import net.nova.nmt.recipe.EnderPotionBrewing;
import net.nova.nmt.recipe.ObsidianTippedArrowRecipe;

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

Expand All @@ -42,8 +41,28 @@ public void register(EmiRegistry registry) {
registry.addCategory(ENDER_BREWING);
registry.addWorkstation(ENDER_BREWING, EmiStack.of(NMTBlocks.ENDER_BREWING_STAND));

addEnderRecipes(registry);
addWorldInteraction(registry);
addEnderRecipes(registry);

for (CraftingRecipe recipe : getRecipes(registry, RecipeType.CRAFTING)) {
if (recipe instanceof ObsidianTippedArrowRecipe) {
NMTPotions.POTIONS.getEntries().forEach(entry -> {
EmiStack arrow = EmiStack.of(Items.ARROW);
addRecipeSafe(registry, () -> new EmiCraftingRecipe(List.of(
arrow, arrow, arrow, arrow,
EmiStack.of(setPotion(new ItemStack(NMTItems.LINGERING_OBSIDIAN_POTION.get()), entry)),
arrow, arrow, arrow, arrow
),
EmiStack.of(setPotion(new ItemStack(NMTItems.OBSIDIAN_TIPPED_ARROW.get(), 8), entry)),
synthetic("crafting/obsidian_tipped_arrow", subId(entry.getId())),
false));
});
}
}
}

public static <C extends RecipeInput, T extends Recipe<C>> Iterable<T> getRecipes(EmiRegistry registry, RecipeType<T> type) {
return registry.getRecipeManager().getAllRecipesFor(type).stream().map(e -> e.value())::iterator;
}

public void addEnderRecipes(EmiRegistry registry) {
Expand All @@ -56,11 +75,11 @@ public void addEnderRecipes(EmiRegistry registry) {
if (recipe.ingredient().getItems().length > 0) {
ResourceLocation id = id("emi", "/ender_brewing/" + pid
+ "/" + subId(recipe.ingredient().getItems()[0].getItem())
+ "/" + subId(BuiltInRegistries.POTION.getKey(recipe.from().value()))
+ "/" + subId(BuiltInRegistries.POTION.getKey(recipe.to().value())));
+ "/" + subId(recipe.from().getKey().location())
+ "/" + subId(recipe.to().getKey().location()));
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));
EmiStack.of(setPotion(stack.copy(), recipe.from())), EmiIngredient.of(recipe.ingredient()),
EmiStack.of(setPotion(stack.copy(), recipe.to())), id));
}
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -76,17 +95,16 @@ public void addEnderRecipes(EmiRegistry registry) {
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 = id("emi", "/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));
EmiStack.of(setPotion(new ItemStack(recipe.from().value()), entry)), EmiIngredient.of(recipe.ingredient()),
EmiStack.of(setPotion(new ItemStack(recipe.to().value()), entry)), id));
}
};
if ((recipe.from().value() instanceof ObsidianPotionItem)) {
BuiltInRegistries.POTION.holders().forEach(potionRecipeGen);
NMTPotions.POTIONS.getEntries().forEach(potionRecipeGen);
} else {
potionRecipeGen.accept(NMTPotions.AWFULLY);
}
Expand All @@ -100,10 +118,10 @@ public void addEnderRecipes(EmiRegistry registry) {

public static void addWorldInteraction(EmiRegistry registry) {
addRecipeSafe(registry, () -> basicWorld(EmiStack.of(NMTItems.OBSIDIAN_GLASS_BOTTLE), EmiStack.of(Fluids.LAVA, 1000),
EmiStack.of(setPotion(new ItemStack(NMTItems.OBSIDIAN_POTION.get()), NMTPotions.LAVA.value())),
EmiStack.of(setPotion(new ItemStack(NMTItems.OBSIDIAN_POTION.get()), NMTPotions.LAVA)),
synthetic("world/unique", "nmt/lava_bottle")));

EmiStack lavaBottle = EmiStack.of(setPotion(new ItemStack(NMTItems.OBSIDIAN_POTION.get()), NMTPotions.LAVA.value()))
EmiStack lavaBottle = EmiStack.of(setPotion(new ItemStack(NMTItems.OBSIDIAN_POTION.get()), NMTPotions.LAVA))
.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));
Expand All @@ -117,8 +135,8 @@ 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);
public static ItemStack setPotion(ItemStack stack, Holder<Potion> potion) {
stack.update(DataComponents.POTION_CONTENTS, PotionContents.EMPTY, potion, PotionContents::withPotion);
return stack;
}

Expand Down

0 comments on commit 35139b5

Please sign in to comment.