Skip to content

Commit

Permalink
done on malum 1.21 fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsterner committed Dec 5, 2024
1 parent 382087f commit 691dc0d
Show file tree
Hide file tree
Showing 34 changed files with 991 additions and 478 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ dependencies {
//modRuntimeOnly("mezz.jei:jei-${property("minecraft_version")}-fabric:${property("jei_version")}")
//EMI
modCompileOnly("dev.emi:emi-fabric:${property("emi_version")}:api")
//modLocalRuntime("dev.emi:emi-fabric:${property("emi_version")}")
modLocalRuntime("dev.emi:emi-fabric:${property("emi_version")}")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${property("rei_version")}")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:${property("rei_version")}")

Expand Down
152 changes: 152 additions & 0 deletions src/main/java/com/sammy/malum/compability/emi/EMIHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.sammy.malum.compability.emi;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.sammy.malum.MalumMod;
import com.sammy.malum.common.recipe.spirit.transmutation.SpiritTransmutationRecipe;
import com.sammy.malum.compability.emi.recipes.*;
import com.sammy.malum.core.systems.recipe.SpiritIngredient;
import com.sammy.malum.forge_stuff.SizedIngredient;
import com.sammy.malum.registry.common.SpiritRiteRegistry;
import com.sammy.malum.registry.common.item.ItemRegistry;
import com.sammy.malum.registry.common.recipe.RecipeTypeRegistry;
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.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder;
import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeInput;
import net.minecraft.world.item.crafting.RecipeType;

import java.util.List;
import java.util.Map;
import java.util.function.Function;


public class EMIHandler implements EmiPlugin {

private static final EmiStack SPIRIT_INFUSION_WORKSTATION = EmiStack.of(ItemRegistry.SPIRIT_ALTAR.get());
public static final EmiRecipeCategory SPIRIT_INFUSION = new EmiRecipeCategory(
MalumMod.malumPath("spirit_infusion"),
SPIRIT_INFUSION_WORKSTATION
);

private static final EmiStack SPIRIT_FOCUSING_WORKSTATION = EmiStack.of(ItemRegistry.SPIRIT_CRUCIBLE.get());
public static final EmiRecipeCategory SPIRIT_FOCUSING = new EmiRecipeCategory(
MalumMod.malumPath("spirit_focusing"),
SPIRIT_FOCUSING_WORKSTATION
);

private static final EmiStack SPIRIT_TRANSMUTATION_WORKSTATION = EmiStack.of(ItemRegistry.SOULWOOD_TOTEM_BASE.get());
public static final EmiRecipeCategory SPIRIT_TRANSMUTATION = new EmiRecipeCategory(
MalumMod.malumPath("spirit_transmutation"),
SPIRIT_TRANSMUTATION_WORKSTATION
);

private static final EmiStack SPIRIT_RITE_WORKSTATION = EmiStack.of(ItemRegistry.RUNEWOOD_TOTEM_BASE.get());
public static final EmiRecipeCategory SPIRIT_RITE = new EmiRecipeCategory(
MalumMod.malumPath("spirit_rite"),
SPIRIT_RITE_WORKSTATION
);

private static final EmiStack SPIRIT_REPAIR_WORKSTATION = EmiStack.of(ItemRegistry.REPAIR_PYLON.get());
public static final EmiRecipeCategory SPIRIT_REPAIR = new EmiRecipeCategory(
MalumMod.malumPath("spirit_repair"),
SPIRIT_REPAIR_WORKSTATION
);

private static final EmiStack RUNEWORKING_WORKSTATION = EmiStack.of(ItemRegistry.RUNIC_WORKBENCH.get());
public static final EmiRecipeCategory RUNEWORKING = new EmiRecipeCategory(
MalumMod.malumPath("runeworking"),
RUNEWORKING_WORKSTATION
);

private static final EmiStack WEEPING_WORKSTATION = EmiStack.of(ItemRegistry.VOID_DEPOT.get());
public static final EmiRecipeCategory WEEPING = new EmiRecipeCategory(
MalumMod.malumPath("weeping_well"),
WEEPING_WORKSTATION
);

@Override
public void register(EmiRegistry registry) {
registry.addCategory(SPIRIT_INFUSION);
registry.addCategory(SPIRIT_FOCUSING);
registry.addCategory(RUNEWORKING);
registry.addCategory(WEEPING);
registry.addCategory(SPIRIT_REPAIR);
registry.addCategory(SPIRIT_TRANSMUTATION);
registry.addCategory(SPIRIT_RITE);

registry.addWorkstation(SPIRIT_INFUSION, SPIRIT_INFUSION_WORKSTATION);
registry.addWorkstation(SPIRIT_FOCUSING, SPIRIT_FOCUSING_WORKSTATION);
registry.addWorkstation(RUNEWORKING, RUNEWORKING_WORKSTATION);
registry.addWorkstation(WEEPING, WEEPING_WORKSTATION);
registry.addWorkstation(SPIRIT_REPAIR, SPIRIT_REPAIR_WORKSTATION);
registry.addWorkstation(SPIRIT_TRANSMUTATION, SPIRIT_TRANSMUTATION_WORKSTATION);
registry.addWorkstation(SPIRIT_RITE, SPIRIT_RITE_WORKSTATION);

var transmutation = registry.getRecipeManager().getAllRecipesFor(RecipeTypeRegistry.SPIRIT_TRANSMUTATION.get());
List<SpiritTransmutationRecipe> leftovers = Lists.newArrayList();
Map<String, List<SpiritTransmutationRecipe>> groups = Maps.newLinkedHashMap();
transmutation.forEach((recipe) ->
{
if (recipe.value().group != null) {
List<SpiritTransmutationRecipe> group = groups.computeIfAbsent(recipe.value().group, (k) -> Lists.newArrayList());
group.add(recipe.value());
} else {
leftovers.add(recipe.value());
}
});
groups.values().stream()
.map(SpiritTransmutationRecipeWrapper::new)
.forEach((recipe) -> registry.addRecipe(new SpiritTransmutationEmiRecipe(recipe)));
leftovers.stream()
.map(List::of)
.map(SpiritTransmutationRecipeWrapper::new)
.forEach((recipe) -> registry.addRecipe(new SpiritTransmutationEmiRecipe(recipe)));

SpiritRiteRegistry.RITES.forEach((rite) -> registry.addRecipe(new SpiritRiteEmiRecipe(rite)));

this.removeHiddenRecipes(registry);
}

private void removeHiddenRecipes(EmiRegistry registry) {

}

public static void addItems(WidgetHolder widgets, int left, int top, boolean vertical, List<EmiIngredient> ingredients) {
int slots = ingredients.size();
if (vertical) {
top -= 10 * (slots - 1);
} else {
left -= 10 * (slots - 1);
}
for (int i = 0; i < slots; i++) {
int offset = i * 20;
int offsetLeft = left + 1 + (vertical ? 0 : offset);
int offsetTop = top + 1 + (vertical ? offset : 0);
widgets.addSlot(ingredients.get(i), offsetLeft, offsetTop).drawBack(false);
}
}

public static EmiIngredient convertIngredientWithCount(SizedIngredient ingredient) {
return EmiIngredient.of(ingredient.ingredient(), ingredient.count());
}

public static List<EmiIngredient> convertIngredientWithCounts(List<SizedIngredient> ingredients) {
return ingredients.stream().map(EMIHandler::convertIngredientWithCount).toList();
}

public static EmiIngredient convertSpiritWithCount(SpiritIngredient spirit) {
return EmiIngredient.of(Ingredient.of(spirit.getSpiritType().getSpiritShard()), spirit.getCount());
}

public static List<EmiIngredient> convertSpiritWithCounts(List<SpiritIngredient> spirits) {
return spirits.stream().map(EMIHandler::convertSpiritWithCount).toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.sammy.malum.compability.emi.recipes;

import com.google.common.collect.Lists;
import com.sammy.malum.MalumMod;
import com.sammy.malum.common.recipe.RunicWorkbenchRecipe;
import com.sammy.malum.compability.emi.EMIHandler;
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.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import static com.sammy.malum.MalumMod.malumPath;

public class RuneworkingEmiRecipe implements EmiRecipe {

private static final ResourceLocation BACKGROUND_LOCATION = MalumMod.malumPath("textures/gui/runeworking_jei.png");

public static final ResourceLocation UID = malumPath("runeworking");
private final RunicWorkbenchRecipe recipe;

private final List<EmiIngredient> primary = Lists.newArrayList();
private final List<EmiIngredient> secondary = Lists.newArrayList();
private final List<EmiStack> output = Lists.newArrayList();

public RuneworkingEmiRecipe(RunicWorkbenchRecipe recipe) {
this.recipe = recipe;

primary.add(EmiIngredient.of(recipe.primaryInput.ingredient()));
secondary.add(EmiIngredient.of(recipe.secondaryInput.toVanilla()));
output.add(EmiStack.of(recipe.output));
}

@Override
public EmiRecipeCategory getCategory() {
return EMIHandler.RUNEWORKING;
}

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

@Override
public List<EmiIngredient> getInputs() {
return primary;
}

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

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

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

@Override
public void addWidgets(WidgetHolder widgets) {
widgets.addTexture(BACKGROUND_LOCATION, 0, 0, this.getDisplayWidth(), this.getDisplayHeight(), 0, 0);

widgets.addSlot(primary.get(0), 63, 14).drawBack(false);
widgets.addSlot(secondary.get(0), 63, 57).drawBack(false);
widgets.addSlot(output.get(0), 63, 124).drawBack(false);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.sammy.malum.compability.emi.recipes;

import com.google.common.collect.Lists;
import com.sammy.malum.MalumMod;
import com.sammy.malum.client.screen.codex.ArcanaCodexHelper;
import com.sammy.malum.common.recipe.spirit.focusing.SpiritFocusingRecipe;
import com.sammy.malum.compability.emi.EMIHandler;
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.resources.ResourceLocation;

import java.util.List;

import static com.sammy.malum.MalumMod.malumPath;

public class SpiritFocusingEmiRecipe implements EmiRecipe {
private static final ResourceLocation BACKGROUND_LOCATION = MalumMod.malumPath("textures/gui/spirit_focusing_jei.png");
public static final ResourceLocation UID = malumPath("spirit_focusing");
private final SpiritFocusingRecipe recipe;

private final List<EmiIngredient> inputs;
private final List<EmiIngredient> spirits;
private final List<EmiStack> result;

public SpiritFocusingEmiRecipe(SpiritFocusingRecipe recipe) {
this.recipe = recipe;

this.inputs = Lists.newArrayList();
this.inputs.add(EmiIngredient.of(recipe.ingredient));
this.inputs.addAll(this.spirits = EMIHandler.convertSpiritWithCounts(recipe.spirits));

this.result = List.of(EmiStack.of(recipe.output));
}

@Override
public EmiRecipeCategory getCategory() {
return EMIHandler.SPIRIT_FOCUSING;
}

@Override
public ResourceLocation getId() {
return UID;
}

@Override
public List<EmiIngredient> getInputs() {
return inputs;
}

@Override
public List<EmiStack> getOutputs() {
return result;
}

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

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

@Override
public void addWidgets(WidgetHolder widgets) {
widgets.addTexture(BACKGROUND_LOCATION, 0, 0, this.getDisplayWidth(), this.getDisplayHeight(), 0, 0);

widgets.addDrawable(0, 0, 0, 0, (guiGraphics, mx, my, d) ->
{
if (!spirits.isEmpty()) {
ArcanaCodexHelper.renderItemFrames(guiGraphics.pose(), recipe.spirits.size(), 61, 12, false);
}
});

EMIHandler.addItems(widgets, 61, 12, false, spirits);

widgets.addSlot(inputs.get(0), 62, 56).catalyst(true).drawBack(false);

widgets.addSlot(result.get(0), 62, 123).recipeContext(this).drawBack(false);
}
}
Loading

0 comments on commit 691dc0d

Please sign in to comment.