Skip to content

Commit

Permalink
feat(EMI): Add option to invert input when CG is merged with EMI
Browse files Browse the repository at this point in the history
Closes #51
  • Loading branch information
null2264 committed Nov 15, 2023
1 parent e552b12 commit 8762717
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ public class ConfigMetaData implements Config
public EMIData emi = new EMIData();

public static class EMIData {
@Comment(value="Add CobbleGen tooltip when CobbleGen is merged with EMI's World Interaction category")
@Comment(value="Add CobbleGen tooltip")
public Boolean addTooltip = true;

@Comment(value="Remove overlapping recipe between CobbleGen and EMI when CobbleGen is merged with EMI's World Interaction category")
@Comment(value="Remove overlapping recipe between CobbleGen and EMI")
public Boolean removeOverlaps = true;

@Comment(value="Invert input position")
public Boolean invertInput = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@
import dev.emi.emi.api.EmiRegistry;
import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.recipe.EmiWorldInteractionRecipe;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.SlotWidget;
import io.github.null2264.cobblegen.CobbleGen;
import io.github.null2264.cobblegen.compat.LoaderCompat;
import io.github.null2264.cobblegen.compat.TextCompat;
import io.github.null2264.cobblegen.config.ConfigMetaData;
import io.github.null2264.cobblegen.config.WeightedBlock;
import io.github.null2264.cobblegen.util.CGLog;
import io.github.null2264.cobblegen.util.Util;
import lombok.val;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.Fluids;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.function.Function;

import static io.github.null2264.cobblegen.CobbleGen.FLUID_INTERACTION;

Expand Down Expand Up @@ -58,6 +57,35 @@ public class CGEMIPlugin implements EmiPlugin
)
);

enum InputPosition {
LEFT, RIGHT
}

private void input(
EmiWorldInteractionRecipe.Builder recipe,
EmiIngredient input,
boolean catalyst,
InputPosition position
) {
if (position.equals(InputPosition.RIGHT))
recipe.rightInput(input, catalyst);
else
recipe.leftInput(input);
}

private void input(
EmiWorldInteractionRecipe.Builder recipe,
EmiIngredient input,
boolean catalyst,
Function<SlotWidget, SlotWidget> mutator,
InputPosition position
) {
if (position.equals(InputPosition.RIGHT))
recipe.rightInput(input, catalyst, mutator);
else
recipe.leftInput(input, mutator);
}

@Override
public void register(EmiRegistry registry) {
if (!CobbleGen.META_CONFIG.enableRecipeViewer)
Expand Down Expand Up @@ -119,19 +147,40 @@ public void register(EmiRegistry registry) {
val id = Util.identifierOf(CGEMIPlugin.ID_PREFIX + generator.getType().name()
.toLowerCase() + "-" + source.toDebugFileName() + "-" + resultId.toDebugFileName() + "-" + neighbourId.toDebugFileName() + "-" + modifierId.toDebugFileName());

EmiWorldInteractionRecipe.Builder recipe = EmiWorldInteractionRecipe.builder()
.id(id)
.leftInput(trigger.copy().setRemainder(trigger));
val recipe = EmiWorldInteractionRecipe.builder()
.id(id);

input(
recipe,
trigger.copy().setRemainder(trigger),
false,
CobbleGen.META_CONFIG.emi.invertInput ? InputPosition.RIGHT : InputPosition.LEFT
);

EmiStack neighbourRemainder = neighbour.isEmpty() ? neighbour : neighbour.copy().setRemainder(neighbour);

if (modifier.isPresent())
recipe.rightInput(EmiStack.of(modifier.get()), false,
s -> s.appendTooltip(TextCompat.translatable("tooltip.emi.fluid_interaction.basalt.soul_soil").withStyle(ChatFormatting.GREEN)))
.rightInput(neighbourRemainder, false,
s -> generator.getBlock() != null ? s.appendTooltip(TextCompat.translatable("tooltip.emi.fluid_interaction.basalt.blue_ice").withStyle(ChatFormatting.GREEN)) : s);
else {
recipe.rightInput(neighbourRemainder, false);
if (modifier.isPresent()) {
input(
recipe,
EmiStack.of(modifier.get()),
false,
s -> s.appendTooltip(TextCompat.translatable("tooltip.emi.fluid_interaction.basalt.soul_soil").withStyle(ChatFormatting.GREEN)),
CobbleGen.META_CONFIG.emi.invertInput ? InputPosition.LEFT : InputPosition.RIGHT
);
input(
recipe,
neighbourRemainder,
false,
s -> generator.getBlock() != null ? s.appendTooltip(TextCompat.translatable("tooltip.emi.fluid_interaction.basalt.blue_ice").withStyle(ChatFormatting.GREEN)) : s,
CobbleGen.META_CONFIG.emi.invertInput ? InputPosition.LEFT : InputPosition.RIGHT
);
} else {
input(
recipe,
neighbourRemainder,
false,
CobbleGen.META_CONFIG.emi.invertInput ? InputPosition.LEFT : InputPosition.RIGHT
);
}

recipe.output(output,
Expand Down

0 comments on commit 8762717

Please sign in to comment.