[Change] Disabled EMI and ModMenu Support for now

This commit is contained in:
Frank 2023-05-17 12:24:06 +02:00
parent 622d77a7fc
commit 4602596e60
8 changed files with 842 additions and 842 deletions

View file

@ -1,118 +1,118 @@
package org.betterx.bclib.integration.emi; package org.betterx.bclib.integration.emi;
import net.minecraft.client.Minecraft; //import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; //import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.resources.ResourceLocation; //import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container; //import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Ingredient; //import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe; //import net.minecraft.world.item.crafting.Recipe;
//
import dev.emi.emi.EmiPort; //import dev.emi.emi.EmiPort;
import dev.emi.emi.api.recipe.EmiRecipe; //import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory; //import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.render.EmiTexture; //import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient; //import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack; //import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder; //import dev.emi.emi.api.widget.WidgetHolder;
//
import java.util.List; //import java.util.List;
//
public abstract class EMIAbstractAlloyingRecipe<C extends Container, T extends Recipe<C>> implements EmiRecipe { //public abstract class EMIAbstractAlloyingRecipe<C extends Container, T extends Recipe<C>> implements EmiRecipe {
private final ResourceLocation id; // private final ResourceLocation id;
private final List<EmiIngredient> input; // private final List<EmiIngredient> input;
private final List<EmiStack> output; // private final List<EmiStack> output;
protected final T recipe; // protected final T recipe;
//
private final int fuelMultiplier; // private final int fuelMultiplier;
private final boolean infiniBurn; // private final boolean infiniBurn;
//
public EMIAbstractAlloyingRecipe(T recipe, ResourceLocation id, int fuelMultiplier, boolean infiniBurn) { // public EMIAbstractAlloyingRecipe(T recipe, ResourceLocation id, int fuelMultiplier, boolean infiniBurn) {
this.recipe = recipe; // this.recipe = recipe;
this.id = id; // this.id = id;
this.input = List.of( // this.input = List.of(
EmiIngredient.of(recipe.getIngredients().get(0)), // EmiIngredient.of(recipe.getIngredients().get(0)),
recipe.getIngredients().size() > 1 // recipe.getIngredients().size() > 1
? EmiIngredient.of(recipe.getIngredients().get(1)) // ? EmiIngredient.of(recipe.getIngredients().get(1))
: EmiIngredient.of(Ingredient.EMPTY) // : EmiIngredient.of(Ingredient.EMPTY)
); // );
//
this.output = List.of(EmiStack.of(recipe.getResultItem(Minecraft.getInstance().level.registryAccess()))); // this.output = List.of(EmiStack.of(recipe.getResultItem(Minecraft.getInstance().level.registryAccess())));
this.fuelMultiplier = fuelMultiplier; // this.fuelMultiplier = fuelMultiplier;
this.infiniBurn = infiniBurn; // this.infiniBurn = infiniBurn;
} // }
//
protected abstract int getSmeltTime(); // protected abstract int getSmeltTime();
protected abstract float getExperience(); // protected abstract float getExperience();
//
//
@Override // @Override
public EmiRecipeCategory getCategory() { // public EmiRecipeCategory getCategory() {
return EMIPlugin.END_ALLOYING_CATEGORY; // return EMIPlugin.END_ALLOYING_CATEGORY;
} // }
//
@Override // @Override
public ResourceLocation getId() { // public ResourceLocation getId() {
return id; // return id;
} // }
//
@Override // @Override
public List<EmiIngredient> getInputs() { // public List<EmiIngredient> getInputs() {
return input; // return input;
} // }
//
@Override // @Override
public List<EmiStack> getOutputs() { // public List<EmiStack> getOutputs() {
return output; // return output;
} // }
//
protected int getXOffset() { // protected int getXOffset() {
return 22; // return 22;
} // }
//
@Override // @Override
public int getDisplayWidth() { // public int getDisplayWidth() {
return 82 + getXOffset(); // return 82 + getXOffset();
} // }
//
@Override // @Override
public int getDisplayHeight() { // public int getDisplayHeight() {
return 38; // return 38;
} // }
//
@Override // @Override
public void addWidgets(WidgetHolder widgets) { // public void addWidgets(WidgetHolder widgets) {
// Add an arrow texture to indicate processing // // Add an arrow texture to indicate processing
widgets.addFillingArrow(24 + getXOffset(), 5, 50 * getSmeltTime()).tooltip((mx, my) -> { // widgets.addFillingArrow(24 + getXOffset(), 5, 50 * getSmeltTime()).tooltip((mx, my) -> {
return List.of(ClientTooltipComponent.create(EmiPort.ordered(EmiPort.translatable( // return List.of(ClientTooltipComponent.create(EmiPort.ordered(EmiPort.translatable(
"emi.cooking.time", // "emi.cooking.time",
new Object[]{(float) getSmeltTime() / 20.0F} // new Object[]{(float) getSmeltTime() / 20.0F}
)))); // ))));
}); // });
//
if (this.infiniBurn) { // if (this.infiniBurn) {
widgets.addTexture(EmiTexture.FULL_FLAME, 1, 24); // widgets.addTexture(EmiTexture.FULL_FLAME, 1, 24);
} else { // } else {
widgets.addTexture(EmiTexture.EMPTY_FLAME, 1, 24); // widgets.addTexture(EmiTexture.EMPTY_FLAME, 1, 24);
widgets.addAnimatedTexture(EmiTexture.FULL_FLAME, 1, 24, 4000 / this.fuelMultiplier, false, true, true); // widgets.addAnimatedTexture(EmiTexture.FULL_FLAME, 1, 24, 4000 / this.fuelMultiplier, false, true, true);
} // }
//
// Adds an input slot on the left // // Adds an input slot on the left
widgets.addSlot(input.get(0), 0, 4); // widgets.addSlot(input.get(0), 0, 4);
widgets.addSlot((input.size() > 1) ? input.get(1) : null, 20, 4); // widgets.addSlot((input.size() > 1) ? input.get(1) : null, 20, 4);
widgets.addText( // widgets.addText(
EmiPort.ordered(EmiPort.translatable("emi.cooking.experience", getExperience())), // EmiPort.ordered(EmiPort.translatable("emi.cooking.experience", getExperience())),
24 + getXOffset(), 28, 0xFFFFFFFF, true // 24 + getXOffset(), 28, 0xFFFFFFFF, true
); // );
//
// Adds an output slot on the right // // Adds an output slot on the right
// Note that output slots need to call `recipeContext` to inform EMI about their recipe context // // Note that output slots need to call `recipeContext` to inform EMI about their recipe context
// This includes being able to resolve recipe trees, favorite stacks with recipe context, and more // // This includes being able to resolve recipe trees, favorite stacks with recipe context, and more
widgets.addSlot(output.get(0), 56 + getXOffset(), 0).output(true).recipeContext(this); // widgets.addSlot(output.get(0), 56 + getXOffset(), 0).output(true).recipeContext(this);
} // }
//
@Override // @Override
public boolean supportsRecipeTree() { // public boolean supportsRecipeTree() {
return true; // return true;
} // }
} //}

View file

@ -1,32 +1,32 @@
package org.betterx.bclib.integration.emi; package org.betterx.bclib.integration.emi;
import org.betterx.bclib.BCLib; //import org.betterx.bclib.BCLib;
import org.betterx.bclib.recipes.AlloyingRecipe; //import org.betterx.bclib.recipes.AlloyingRecipe;
//
import net.minecraft.world.Container; //import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.RecipeManager; //import net.minecraft.world.item.crafting.RecipeManager;
//
import dev.emi.emi.api.EmiRegistry; //import dev.emi.emi.api.EmiRegistry;
//
public class EMIAlloyingRecipe extends EMIAbstractAlloyingRecipe<Container, AlloyingRecipe> { //public class EMIAlloyingRecipe extends EMIAbstractAlloyingRecipe<Container, AlloyingRecipe> {
public EMIAlloyingRecipe(AlloyingRecipe recipe) { // public EMIAlloyingRecipe(AlloyingRecipe recipe) {
super(recipe, recipe.getId(), 1, false); // super(recipe, recipe.getId(), 1, false);
} // }
//
@Override // @Override
protected int getSmeltTime() { // protected int getSmeltTime() {
return recipe.getSmeltTime(); // return recipe.getSmeltTime();
} // }
//
@Override // @Override
protected float getExperience() { // protected float getExperience() {
return recipe.getExperience(); // return recipe.getExperience();
} // }
//
static void addAllRecipes(EmiRegistry emiRegistry, RecipeManager manager) { // static void addAllRecipes(EmiRegistry emiRegistry, RecipeManager manager) {
EMIPlugin.addAllRecipes( // EMIPlugin.addAllRecipes(
emiRegistry, manager, BCLib.LOGGER, // emiRegistry, manager, BCLib.LOGGER,
AlloyingRecipe.TYPE, EMIAlloyingRecipe::new // AlloyingRecipe.TYPE, EMIAlloyingRecipe::new
); // );
} // }
} //}

View file

@ -1,111 +1,111 @@
package org.betterx.bclib.integration.emi; package org.betterx.bclib.integration.emi;
import org.betterx.bclib.BCLib; //import org.betterx.bclib.BCLib;
import org.betterx.bclib.recipes.AnvilRecipe; //import org.betterx.bclib.recipes.AnvilRecipe;
//
import net.minecraft.client.Minecraft; //import net.minecraft.client.Minecraft;
import net.minecraft.core.Holder; //import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation; //import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item; //import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.Ingredient; //import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeManager; //import net.minecraft.world.item.crafting.RecipeManager;
//
import dev.emi.emi.api.EmiRegistry; //import dev.emi.emi.api.EmiRegistry;
import dev.emi.emi.api.recipe.EmiRecipe; //import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory; //import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.render.EmiTexture; //import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiIngredient; //import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack; //import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.widget.WidgetHolder; //import dev.emi.emi.api.widget.WidgetHolder;
//
import java.util.List; //import java.util.List;
import java.util.stream.StreamSupport; //import java.util.stream.StreamSupport;
import org.jetbrains.annotations.Nullable; //import org.jetbrains.annotations.Nullable;
//
public class EMIAnvilRecipe implements EmiRecipe { //public class EMIAnvilRecipe implements EmiRecipe {
private final ResourceLocation id; // private final ResourceLocation id;
private final List<EmiIngredient> input; // private final List<EmiIngredient> input;
private final List<EmiStack> output; // private final List<EmiStack> output;
private final EmiRecipeCategory category; // private final EmiRecipeCategory category;
//
public EMIAnvilRecipe(AnvilRecipe recipe, Item hammer) { // public EMIAnvilRecipe(AnvilRecipe recipe, Item hammer) {
this.id = new ResourceLocation( // this.id = new ResourceLocation(
"emi", // "emi",
recipe.getId().getNamespace() + "/" + recipe.getId().getPath() + "/anvil/" + hammer.getDescriptionId() // recipe.getId().getNamespace() + "/" + recipe.getId().getPath() + "/anvil/" + hammer.getDescriptionId()
); // );
this.input = List.of( // this.input = List.of(
EmiIngredient.of(recipe.getMainIngredient(), recipe.getInputCount()), // EmiIngredient.of(recipe.getMainIngredient(), recipe.getInputCount()),
EmiIngredient.of(Ingredient.of(hammer)) // EmiIngredient.of(Ingredient.of(hammer))
); // );
this.output = List.of(EmiStack.of(recipe.getResultItem(Minecraft.getInstance().level.registryAccess()))); // this.output = List.of(EmiStack.of(recipe.getResultItem(Minecraft.getInstance().level.registryAccess())));
this.category = EMIPlugin.getAnvilCategoryForLevel(recipe.getAnvilLevel()); // this.category = EMIPlugin.getAnvilCategoryForLevel(recipe.getAnvilLevel());
} // }
//
static void addAllRecipes(EmiRegistry emiRegistry, RecipeManager manager) { // static void addAllRecipes(EmiRegistry emiRegistry, RecipeManager manager) {
Iterable<Holder<Item>> hammers = AnvilRecipe.getAllHammers(); // Iterable<Holder<Item>> hammers = AnvilRecipe.getAllHammers();
EMIPlugin.addAllRecipes( // EMIPlugin.addAllRecipes(
emiRegistry, manager, BCLib.LOGGER, // emiRegistry, manager, BCLib.LOGGER,
AnvilRecipe.TYPE, // AnvilRecipe.TYPE,
recipe -> StreamSupport.stream(hammers.spliterator(), false) // recipe -> StreamSupport.stream(hammers.spliterator(), false)
.map(Holder::value) // .map(Holder::value)
.filter(recipe::canUse) // .filter(recipe::canUse)
.toList(), // .toList(),
EMIAnvilRecipe::new // EMIAnvilRecipe::new
); // );
} // }
//
@Override // @Override
public EmiRecipeCategory getCategory() { // public EmiRecipeCategory getCategory() {
return category; // return category;
} // }
//
@Override // @Override
public @Nullable ResourceLocation getId() { // public @Nullable ResourceLocation getId() {
return id; // return id;
} // }
//
@Override // @Override
public List<EmiIngredient> getInputs() { // public List<EmiIngredient> getInputs() {
return input; // return input;
} // }
//
@Override // @Override
public List<EmiStack> getOutputs() { // public List<EmiStack> getOutputs() {
return output; // return output;
} // }
//
@Override // @Override
public int getDisplayWidth() { // public int getDisplayWidth() {
return 104; // return 104;
} // }
//
@Override // @Override
public int getDisplayHeight() { // public int getDisplayHeight() {
return 26; // return 26;
} // }
//
@Override // @Override
public void addWidgets(WidgetHolder widgetHolder) { // public void addWidgets(WidgetHolder widgetHolder) {
// Add an arrow texture to indicate processing // // Add an arrow texture to indicate processing
widgetHolder.addTexture(EmiTexture.EMPTY_ARROW, 46, 5); // widgetHolder.addTexture(EmiTexture.EMPTY_ARROW, 46, 5);
//
// Adds an input slot on the left // // Adds an input slot on the left
widgetHolder.addSlot(input.get(0), 0, 4); // widgetHolder.addSlot(input.get(0), 0, 4);
widgetHolder.addSlot(input.get(1), 20, 4).catalyst(true); // widgetHolder.addSlot(input.get(1), 20, 4).catalyst(true);
//
// Adds an output slot on the right // // Adds an output slot on the right
// Note that output slots need to call `recipeContext` to inform EMI about their recipe context // // Note that output slots need to call `recipeContext` to inform EMI about their recipe context
// This includes being able to resolve recipe trees, favorite stacks with recipe context, and more // // This includes being able to resolve recipe trees, favorite stacks with recipe context, and more
widgetHolder.addSlot(output.get(0), 78, 0).output(true).recipeContext(this); // widgetHolder.addSlot(output.get(0), 78, 0).output(true).recipeContext(this);
} // }
//
@Override // @Override
public List<EmiIngredient> getCatalysts() { // public List<EmiIngredient> getCatalysts() {
return List.of(input.get(1)); // return List.of(input.get(1));
} // }
//
@Override // @Override
public boolean supportsRecipeTree() { // public boolean supportsRecipeTree() {
return true; // return true;
} // }
} //}

View file

@ -1,191 +1,191 @@
package org.betterx.bclib.integration.emi; package org.betterx.bclib.integration.emi;
import org.betterx.bclib.blocks.LeveledAnvilBlock; //import org.betterx.bclib.blocks.LeveledAnvilBlock;
import org.betterx.bclib.util.RomanNumeral; //import org.betterx.bclib.util.RomanNumeral;
//
import com.mojang.blaze3d.vertex.PoseStack; //import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator; //import com.mojang.blaze3d.vertex.Tesselator;
import net.minecraft.ChatFormatting; //import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft; //import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font; //import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; //import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.renderer.MultiBufferSource; //import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.resources.ResourceLocation; //import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence; //import net.minecraft.util.FormattedCharSequence;
//
import com.google.common.collect.Lists; //import com.google.common.collect.Lists;
import dev.emi.emi.EmiPort; //import dev.emi.emi.EmiPort;
import dev.emi.emi.EmiUtil; //import dev.emi.emi.EmiUtil;
import dev.emi.emi.api.recipe.EmiRecipe; //import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory; //import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.render.EmiRenderable; //import dev.emi.emi.api.render.EmiRenderable;
import dev.emi.emi.api.render.EmiTexture; //import dev.emi.emi.api.render.EmiTexture;
import org.joml.Matrix4f; //import org.joml.Matrix4f;
//
import java.util.Comparator; //import java.util.Comparator;
import java.util.List; //import java.util.List;
//
public class EMIAnvilRecipeCategory extends EmiRecipeCategory { //public class EMIAnvilRecipeCategory extends EmiRecipeCategory {
private final int anvilLevel; // private final int anvilLevel;
private final List<FormattedCharSequence> titleLines; // private final List<FormattedCharSequence> titleLines;
//
//
public EMIAnvilRecipeCategory(ResourceLocation id, EmiRenderable icon, int anvilLevel) { // public EMIAnvilRecipeCategory(ResourceLocation id, EmiRenderable icon, int anvilLevel) {
super(id, icon); // super(id, icon);
this.anvilLevel = anvilLevel; // this.anvilLevel = anvilLevel;
titleLines = LeveledAnvilBlock.getNamesForLevel(anvilLevel); // titleLines = LeveledAnvilBlock.getNamesForLevel(anvilLevel);
} // }
//
public EMIAnvilRecipeCategory(ResourceLocation id, EmiRenderable icon, EmiRenderable simplified, int anvilLevel) { // public EMIAnvilRecipeCategory(ResourceLocation id, EmiRenderable icon, EmiRenderable simplified, int anvilLevel) {
super(id, icon, simplified); // super(id, icon, simplified);
this.anvilLevel = anvilLevel; // this.anvilLevel = anvilLevel;
titleLines = LeveledAnvilBlock.getNamesForLevel(anvilLevel); // titleLines = LeveledAnvilBlock.getNamesForLevel(anvilLevel);
} // }
//
public EMIAnvilRecipeCategory( // public EMIAnvilRecipeCategory(
ResourceLocation id, // ResourceLocation id,
EmiRenderable icon, EmiTexture simplified, // EmiRenderable icon, EmiTexture simplified,
Comparator<EmiRecipe> sorter, // Comparator<EmiRecipe> sorter,
int anvilLevel // int anvilLevel
) { // ) {
super(id, icon, simplified, sorter); // super(id, icon, simplified, sorter);
this.anvilLevel = anvilLevel; // this.anvilLevel = anvilLevel;
titleLines = LeveledAnvilBlock.getNamesForLevel(anvilLevel); // titleLines = LeveledAnvilBlock.getNamesForLevel(anvilLevel);
//
//
} // }
//
@Override // @Override
public void renderSimplified(PoseStack stack, int x, int y, float delta) { // public void renderSimplified(PoseStack stack, int x, int y, float delta) {
super.renderSimplified(stack, x, y, delta); // super.renderSimplified(stack, x, y, delta);
final Font font = Minecraft.getInstance().font; // final Font font = Minecraft.getInstance().font;
final String content = RomanNumeral.toRoman(anvilLevel); // final String content = RomanNumeral.toRoman(anvilLevel);
//
final MultiBufferSource.BufferSource bufferSource = MultiBufferSource // final MultiBufferSource.BufferSource bufferSource = MultiBufferSource
.immediate(Tesselator.getInstance().getBuilder()); // .immediate(Tesselator.getInstance().getBuilder());
final int xx = x + 19 - 2 - font.width(content); // final int xx = x + 19 - 2 - font.width(content);
final int yy = y + 6 + 3; // final int yy = y + 6 + 3;
final Matrix4f matrix = stack.last().pose(); // final Matrix4f matrix = stack.last().pose();
//
font.drawInBatch( // font.drawInBatch(
content, // content,
xx - 1, // xx - 1,
yy - 1, // yy - 1,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
font.drawInBatch( // font.drawInBatch(
content, // content,
xx, // xx,
yy - 1, // yy - 1,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
font.drawInBatch( // font.drawInBatch(
content, // content,
xx + 1, // xx + 1,
yy - 1, // yy - 1,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
font.drawInBatch( // font.drawInBatch(
content, // content,
xx - 1, // xx - 1,
yy, // yy,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
font.drawInBatch( // font.drawInBatch(
content, // content,
xx + 1, // xx + 1,
yy, // yy,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
font.drawInBatch( // font.drawInBatch(
content, // content,
xx - 1, // xx - 1,
yy + 1, // yy + 1,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
font.drawInBatch( // font.drawInBatch(
content, // content,
xx + 1, // xx + 1,
yy + 1, // yy + 1,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
font.drawInBatch( // font.drawInBatch(
content, // content,
xx, // xx,
yy + 1, // yy + 1,
0xFF000000, // 0xFF000000,
false, // false,
matrix, // matrix,
bufferSource, // bufferSource,
Font.DisplayMode.NORMAL, // Font.DisplayMode.NORMAL,
0, // 0,
0xF000F0 // 0xF000F0
); // );
//
font.drawInBatch(content, xx, yy, 0xFFFFFFFF, true, matrix, bufferSource, Font.DisplayMode.NORMAL, 0, 0xF000F0); // font.drawInBatch(content, xx, yy, 0xFFFFFFFF, true, matrix, bufferSource, Font.DisplayMode.NORMAL, 0, 0xF000F0);
bufferSource.endBatch(); // bufferSource.endBatch();
} // }
//
public List<ClientTooltipComponent> getTooltip() { // public List<ClientTooltipComponent> getTooltip() {
List<ClientTooltipComponent> list = Lists.newArrayList(); // List<ClientTooltipComponent> list = Lists.newArrayList();
if (titleLines.isEmpty()) { // if (titleLines.isEmpty()) {
list.add(ClientTooltipComponent.create(EmiPort.ordered(EmiPort.translatable(EmiUtil.translateId( // list.add(ClientTooltipComponent.create(EmiPort.ordered(EmiPort.translatable(EmiUtil.translateId(
"emi.category.", // "emi.category.",
this.getId() // this.getId()
))))); // )))));
} else { // } else {
for (var line : titleLines) // for (var line : titleLines)
list.add(ClientTooltipComponent.create(line)); // list.add(ClientTooltipComponent.create(line));
} // }
//
//
list.add(ClientTooltipComponent.create(EmiPort.ordered(EmiPort.literal( // list.add(ClientTooltipComponent.create(EmiPort.ordered(EmiPort.literal(
EmiUtil.getModName(this.getId() // EmiUtil.getModName(this.getId()
.getNamespace()), // .getNamespace()),
new ChatFormatting[]{ChatFormatting.BLUE, ChatFormatting.ITALIC} // new ChatFormatting[]{ChatFormatting.BLUE, ChatFormatting.ITALIC}
)))); // ))));
return list; // return list;
} // }
} //}

View file

@ -1,170 +1,170 @@
package org.betterx.bclib.integration.emi; package org.betterx.bclib.integration.emi;
import org.betterx.bclib.BCLib; //import org.betterx.bclib.BCLib;
import org.betterx.bclib.blocks.LeveledAnvilBlock; //import org.betterx.bclib.blocks.LeveledAnvilBlock;
import org.betterx.bclib.interfaces.AlloyingRecipeWorkstation; //import org.betterx.bclib.interfaces.AlloyingRecipeWorkstation;
import org.betterx.worlds.together.util.Logger; //import org.betterx.worlds.together.util.Logger;
//
import net.minecraft.resources.ResourceLocation; //import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container; //import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe; //import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeManager; //import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType; //import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.Blocks; //import net.minecraft.world.level.block.Blocks;
//
import dev.emi.emi.api.EmiPlugin; //import dev.emi.emi.api.EmiPlugin;
import dev.emi.emi.api.EmiRegistry; //import dev.emi.emi.api.EmiRegistry;
import dev.emi.emi.api.recipe.EmiRecipe; //import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory; //import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.render.EmiTexture; //import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.stack.EmiStack; //import dev.emi.emi.api.stack.EmiStack;
//
import java.util.Comparator; //import java.util.Comparator;
import java.util.List; //import java.util.List;
import java.util.function.BiFunction; //import java.util.function.BiFunction;
import java.util.function.Function; //import java.util.function.Function;
//
public class EMIPlugin implements EmiPlugin { //public class EMIPlugin implements EmiPlugin {
private static boolean didInit = false; // private static boolean didInit = false;
private static int maxAnvilLevel = 1; // private static int maxAnvilLevel = 1;
public static final ResourceLocation BCL_SIMPLIFIED_SPRITES = BCLib.makeID( // public static final ResourceLocation BCL_SIMPLIFIED_SPRITES = BCLib.makeID(
"textures/gui/widgets.png" // "textures/gui/widgets.png"
); // );
//
public static EmiStack END_ALLOYING_WORKSTATION; // public static EmiStack END_ALLOYING_WORKSTATION;
public static EmiRecipeCategory END_ALLOYING_CATEGORY; // public static EmiRecipeCategory END_ALLOYING_CATEGORY;
//
public static EmiRecipeCategory[] ANVIL_CATEGORIES; // public static EmiRecipeCategory[] ANVIL_CATEGORIES;
public static EmiStack[] ANVIL_WORKSTATIONS; // public static EmiStack[] ANVIL_WORKSTATIONS;
//
public static EmiTexture getSprite(int u, int v) { // public static EmiTexture getSprite(int u, int v) {
return new EmiTexture(BCL_SIMPLIFIED_SPRITES, u, v, 16, 16, 16, 16, 32, 32); // return new EmiTexture(BCL_SIMPLIFIED_SPRITES, u, v, 16, 16, 16, 16, 32, 32);
} // }
//
public void lazyInit() { // public void lazyInit() {
if (!didInit) { // if (!didInit) {
didInit = true; // didInit = true;
lazyInitAlloyingCategory(); // lazyInitAlloyingCategory();
lazyInitAnvilCategories(); // lazyInitAnvilCategories();
} // }
} // }
//
private void lazyInitAlloyingCategory() { // private void lazyInitAlloyingCategory() {
var workstations = AlloyingRecipeWorkstation.getWorkstationIcon(); // var workstations = AlloyingRecipeWorkstation.getWorkstationIcon();
if (!workstations.is(Blocks.BARRIER.asItem())) { // if (!workstations.is(Blocks.BARRIER.asItem())) {
END_ALLOYING_WORKSTATION = EmiStack.of(workstations); // END_ALLOYING_WORKSTATION = EmiStack.of(workstations);
//
END_ALLOYING_CATEGORY = new EmiRecipeCategory( // END_ALLOYING_CATEGORY = new EmiRecipeCategory(
BCLib.makeID("alloying"), // BCLib.makeID("alloying"),
END_ALLOYING_WORKSTATION, // END_ALLOYING_WORKSTATION,
getSprite(16, 0) // getSprite(16, 0)
); // );
} // }
} // }
//
//
private void lazyInitAnvilCategories() { // private void lazyInitAnvilCategories() {
if (ANVIL_CATEGORIES == null) { // if (ANVIL_CATEGORIES == null) {
maxAnvilLevel = Math.max(1, LeveledAnvilBlock // maxAnvilLevel = Math.max(1, LeveledAnvilBlock
.getAnvils() // .getAnvils()
.stream() // .stream()
.map(LeveledAnvilBlock::getAnvilCraftingLevel) // .map(LeveledAnvilBlock::getAnvilCraftingLevel)
.reduce(0, Math::max) // .reduce(0, Math::max)
); // );
//
ANVIL_CATEGORIES = new EmiRecipeCategory[maxAnvilLevel + 1]; // ANVIL_CATEGORIES = new EmiRecipeCategory[maxAnvilLevel + 1];
ANVIL_WORKSTATIONS = new EmiStack[maxAnvilLevel + 1]; // ANVIL_WORKSTATIONS = new EmiStack[maxAnvilLevel + 1];
//
for (int anvilLevel = 0; anvilLevel <= maxAnvilLevel; anvilLevel++) { // for (int anvilLevel = 0; anvilLevel <= maxAnvilLevel; anvilLevel++) {
int finalAnvilLevel = anvilLevel; // int finalAnvilLevel = anvilLevel;
ANVIL_WORKSTATIONS[anvilLevel] = EmiStack.of(LeveledAnvilBlock // ANVIL_WORKSTATIONS[anvilLevel] = EmiStack.of(LeveledAnvilBlock
.getAnvils() // .getAnvils()
.stream() // .stream()
.filter(b -> LeveledAnvilBlock.canHandle(b, finalAnvilLevel)) // .filter(b -> LeveledAnvilBlock.canHandle(b, finalAnvilLevel))
.sorted(Comparator.comparingInt(LeveledAnvilBlock::getAnvilCraftingLevel)) // .sorted(Comparator.comparingInt(LeveledAnvilBlock::getAnvilCraftingLevel))
.findFirst().orElse(Blocks.BARRIER) // .findFirst().orElse(Blocks.BARRIER)
); // );
ANVIL_CATEGORIES[anvilLevel] = new EMIAnvilRecipeCategory( // ANVIL_CATEGORIES[anvilLevel] = new EMIAnvilRecipeCategory(
BCLib.makeID("anvil_" + anvilLevel), // BCLib.makeID("anvil_" + anvilLevel),
ANVIL_WORKSTATIONS[anvilLevel], // ANVIL_WORKSTATIONS[anvilLevel],
getSprite(0, 0), // getSprite(0, 0),
anvilLevel // anvilLevel
); // );
//
if (anvilLevel > 0 && ANVIL_WORKSTATIONS[anvilLevel].isEqual(ANVIL_WORKSTATIONS[anvilLevel - 1])) { // if (anvilLevel > 0 && ANVIL_WORKSTATIONS[anvilLevel].isEqual(ANVIL_WORKSTATIONS[anvilLevel - 1])) {
ANVIL_WORKSTATIONS[anvilLevel - 1] = ANVIL_WORKSTATIONS[anvilLevel]; // ANVIL_WORKSTATIONS[anvilLevel - 1] = ANVIL_WORKSTATIONS[anvilLevel];
ANVIL_CATEGORIES[anvilLevel - 1] = ANVIL_CATEGORIES[anvilLevel]; // ANVIL_CATEGORIES[anvilLevel - 1] = ANVIL_CATEGORIES[anvilLevel];
} // }
} // }
} // }
} // }
//
//
@Override // @Override
public void register(EmiRegistry emiRegistry) { // public void register(EmiRegistry emiRegistry) {
lazyInit(); // lazyInit();
final RecipeManager manager = emiRegistry.getRecipeManager(); // final RecipeManager manager = emiRegistry.getRecipeManager();
//
if (END_ALLOYING_CATEGORY != null && END_ALLOYING_WORKSTATION != null) { // if (END_ALLOYING_CATEGORY != null && END_ALLOYING_WORKSTATION != null) {
emiRegistry.addCategory(END_ALLOYING_CATEGORY); // emiRegistry.addCategory(END_ALLOYING_CATEGORY);
emiRegistry.addWorkstation(END_ALLOYING_CATEGORY, END_ALLOYING_WORKSTATION); // emiRegistry.addWorkstation(END_ALLOYING_CATEGORY, END_ALLOYING_WORKSTATION);
//
EMIAlloyingRecipe.addAllRecipes(emiRegistry, manager); // EMIAlloyingRecipe.addAllRecipes(emiRegistry, manager);
} // }
//
if (ANVIL_CATEGORIES != null && ANVIL_WORKSTATIONS != null && ANVIL_CATEGORIES.length > 0) { // if (ANVIL_CATEGORIES != null && ANVIL_WORKSTATIONS != null && ANVIL_CATEGORIES.length > 0) {
for (int i = 0; i <= maxAnvilLevel; i++) { // for (int i = 0; i <= maxAnvilLevel; i++) {
emiRegistry.addCategory(ANVIL_CATEGORIES[i]); // emiRegistry.addCategory(ANVIL_CATEGORIES[i]);
emiRegistry.addWorkstation(ANVIL_CATEGORIES[i], ANVIL_WORKSTATIONS[i]); // emiRegistry.addWorkstation(ANVIL_CATEGORIES[i], ANVIL_WORKSTATIONS[i]);
} // }
EMIAnvilRecipe.addAllRecipes(emiRegistry, manager); // EMIAnvilRecipe.addAllRecipes(emiRegistry, manager);
} // }
} // }
//
public static <C extends Container, T extends Recipe<C>, E extends EmiRecipe> void addAllRecipes( // public static <C extends Container, T extends Recipe<C>, E extends EmiRecipe> void addAllRecipes(
EmiRegistry emiRegistry, // EmiRegistry emiRegistry,
RecipeManager manager, // RecipeManager manager,
Logger logger, // Logger logger,
RecipeType<T> recipeType, // RecipeType<T> recipeType,
Function<T, E> createRecipe // Function<T, E> createRecipe
) { // ) {
addAllRecipes( // addAllRecipes(
emiRegistry, // emiRegistry,
manager, // manager,
logger, // logger,
recipeType, // recipeType,
(_ignored) -> null, // (_ignored) -> null,
(recipe, _ignored) -> createRecipe.apply(recipe) // (recipe, _ignored) -> createRecipe.apply(recipe)
); // );
} // }
//
public static <C extends Container, T extends Recipe<C>, E extends EmiRecipe, V> void addAllRecipes( // public static <C extends Container, T extends Recipe<C>, E extends EmiRecipe, V> void addAllRecipes(
EmiRegistry emiRegistry, // EmiRegistry emiRegistry,
RecipeManager manager, // RecipeManager manager,
Logger logger, // Logger logger,
RecipeType<T> recipeType, // RecipeType<T> recipeType,
Function<T, List<V>> variantSupplier, // Function<T, List<V>> variantSupplier,
BiFunction<T, V, E> createRecipe // BiFunction<T, V, E> createRecipe
) { // ) {
for (T recipe : manager.getAllRecipesFor(recipeType)) { // for (T recipe : manager.getAllRecipesFor(recipeType)) {
List<V> variants = variantSupplier.apply(recipe); // List<V> variants = variantSupplier.apply(recipe);
if (variants == null) { // if (variants == null) {
emiRegistry.addRecipe(createRecipe.apply(recipe, null)); // emiRegistry.addRecipe(createRecipe.apply(recipe, null));
} else { // } else {
for (V variantData : variants) { // for (V variantData : variants) {
try { // try {
emiRegistry.addRecipe(createRecipe.apply(recipe, variantData)); // emiRegistry.addRecipe(createRecipe.apply(recipe, variantData));
} catch (Exception e) { // } catch (Exception e) {
logger.error("Exception when parsing vanilla recipe " + recipe.getId(), e); // logger.error("Exception when parsing vanilla recipe " + recipe.getId(), e);
} // }
} // }
} // }
} // }
} // }
//
//
static EmiRecipeCategory getAnvilCategoryForLevel(int anvilLevel) { // static EmiRecipeCategory getAnvilCategoryForLevel(int anvilLevel) {
anvilLevel = Math.max(0, Math.min(ANVIL_CATEGORIES.length - 1, anvilLevel)); // anvilLevel = Math.max(0, Math.min(ANVIL_CATEGORIES.length - 1, anvilLevel));
return ANVIL_CATEGORIES[anvilLevel]; // return ANVIL_CATEGORIES[anvilLevel];
} // }
} //}

View file

@ -1,30 +1,30 @@
package org.betterx.bclib.integration.modmenu; package org.betterx.bclib.integration.modmenu;
import net.minecraft.client.gui.screens.Screen; //import net.minecraft.client.gui.screens.Screen;
//
import java.util.HashMap; //import java.util.HashMap;
import java.util.Map; //import java.util.Map;
import java.util.function.Function; //import java.util.function.Function;
//
/** ///**
* Integration, to provide a custom Screen for ModMenu. // * Integration, to provide a custom Screen for ModMenu.
* <p> // * <p>
* This integration allows you to use ModMenu without adding a dependency to your project. If the // * This integration allows you to use ModMenu without adding a dependency to your project. If the
* Mod is installed on the Client. // * Mod is installed on the Client.
* <p> // * <p>
* You can add a screen for your mod by calling {@link #addModMenuScreen(String, Function)} // * You can add a screen for your mod by calling {@link #addModMenuScreen(String, Function)}
*/ // */
public class ModMenu { //public class ModMenu {
static final Map<String, Function<Screen, Screen>> screen = new HashMap<>(); // static final Map<String, Function<Screen, Screen>> screen = new HashMap<>();
//
/** // /**
* registers a ModMenu entrypoint for another Mod. For Example {@code addModMenuScreen("myMod", (parent)->new Screen(parent));} // * registers a ModMenu entrypoint for another Mod. For Example {@code addModMenuScreen("myMod", (parent)->new Screen(parent));}
* // *
* @param modID The ID of your Mod // * @param modID The ID of your Mod
* @param scr a function that takes a parent {@link Screen} and provides the main Screen you want // * @param scr a function that takes a parent {@link Screen} and provides the main Screen you want
* to show with ModMenu for your Mod. // * to show with ModMenu for your Mod.
*/ // */
public static void addModMenuScreen(String modID, Function<Screen, Screen> scr) { // public static void addModMenuScreen(String modID, Function<Screen, Screen> scr) {
screen.put(modID, scr); // screen.put(modID, scr);
} // }
} //}

View file

@ -1,34 +1,34 @@
package org.betterx.bclib.integration.modmenu; package org.betterx.bclib.integration.modmenu;
import org.betterx.bclib.client.gui.modmenu.MainScreen; //import org.betterx.bclib.client.gui.modmenu.MainScreen;
//
import com.terraformersmc.modmenu.api.ConfigScreenFactory; //import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi; //import com.terraformersmc.modmenu.api.ModMenuApi;
//
import java.util.HashMap; //import java.util.HashMap;
import java.util.Map; //import java.util.Map;
import java.util.function.Function; //import java.util.function.Function;
//
//
/** ///**
* Internal class to hook into ModMenu, you should not need to use this class. If you want to register a // * Internal class to hook into ModMenu, you should not need to use this class. If you want to register a
* ModMenu Screen for a Mod using BCLib, use {@link ModMenu#addModMenuScreen(String, Function)} // * ModMenu Screen for a Mod using BCLib, use {@link ModMenu#addModMenuScreen(String, Function)}
*/ // */
public class ModMenuEntryPoint implements ModMenuApi { //public class ModMenuEntryPoint implements ModMenuApi {
@Override // @Override
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() { // public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
Map<String, ConfigScreenFactory<?>> copy = new HashMap<>(); // Map<String, ConfigScreenFactory<?>> copy = new HashMap<>();
for (var entry : ModMenu.screen.entrySet()) { // for (var entry : ModMenu.screen.entrySet()) {
copy.put(entry.getKey(), (parent) -> entry.getValue().apply(parent)); // copy.put(entry.getKey(), (parent) -> entry.getValue().apply(parent));
} // }
return copy; // return copy;
} // }
//
@Override // @Override
public ConfigScreenFactory<?> getModConfigScreenFactory() { // public ConfigScreenFactory<?> getModConfigScreenFactory() {
//return (parent) -> new TestScreen(parent, Component.literal("Hello Test")); // //return (parent) -> new TestScreen(parent, Component.literal("Hello Test"));
return (parent) -> new MainScreen(parent); // return (parent) -> new MainScreen(parent);
} // }
//
//
} //}

View file

@ -1,88 +1,35 @@
package org.betterx.bclib.integration.modmenu; package org.betterx.bclib.integration.modmenu;
import org.betterx.bclib.integration.modmenu.ModMenuIntegration.ModMenuScreenFactory; //import org.betterx.bclib.integration.modmenu.ModMenuIntegration.ModMenuScreenFactory;
//
import net.minecraft.client.gui.screens.Screen; //import net.minecraft.client.gui.screens.Screen;
//
import com.google.common.collect.ImmutableMap; //import com.google.common.collect.ImmutableMap;
//
import java.lang.reflect.InvocationHandler; //import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; //import java.lang.reflect.Method;
import java.lang.reflect.Proxy; //import java.lang.reflect.Proxy;
import java.util.Map; //import java.util.Map;
//
@Deprecated //@Deprecated
class ModMenuScreenFactoryImpl { //class ModMenuScreenFactoryImpl {
record ScreenFactoryInvocationHandler(ModMenuScreenFactory act) implements InvocationHandler { // record ScreenFactoryInvocationHandler(ModMenuScreenFactory act) implements InvocationHandler {
@Override // @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// return switch (method.getName()) { //// return switch (method.getName()) {
// case "toString" -> ""; //// case "toString" -> "";
// case "equals" -> false; //// case "equals" -> false;
// case "hashCode" -> 0; //// case "hashCode" -> 0;
// default -> act.create((Screen) args[0]); //// default -> act.create((Screen) args[0]);
// }; //// };
return null; // return null;
} // }
} // }
//
public static ModMenuScreenFactory create(ModMenuScreenFactory act) { // public static ModMenuScreenFactory create(ModMenuScreenFactory act) {
Class<?> iConfigScreenFactory = null; // Class<?> iConfigScreenFactory = null;
try {
iConfigScreenFactory = Class.forName("com.terraformersmc.modmenu.api.ConfigScreenFactory");
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
Object o = Proxy.newProxyInstance(
ModMenuIntegration.class.getClassLoader(),
new Class[]{iConfigScreenFactory, ModMenuScreenFactory.class},
new ScreenFactoryInvocationHandler(act)
);
return (ModMenuScreenFactory) o;
}
}
@Deprecated
/**
* Integration, to provide a custom Screen for ModMenu.
* <p>
* This integration allows you to use ModMenu without adding a dependency to your project. If the
* Mod is installed on the Client, and the correct ModMenu-EntryPoint is registered in your <i>fabric.mod.json</i>
* the screen will show up.
* <p>
* You only need to subclass this class, and initialize a static Field of Type {@link ModMenuApi} using
* the {@link #createEntrypoint(ModMenuIntegration)}-Method.
* <p>
* Example:
* <pre>{@code public class ModMenu extends ModMenuIntegration {
* public static final ModMenuApiMarker entrypointObject = createEntrypoint(new EntryPoint());
*
* public EntryPoint() {
* super(GridScreen::new);
* }
* }}</pre>
* You'd also need to add the ModMenu-Entrypoint to your <i>fabric.mod.json</i>:
* <pre>"entrypoints": {
* ...
* "modmenu": [ "your.mod.ModMenu::entrypointObject" ]
* }</pre>
*/
public abstract class ModMenuIntegration {
/**
* Creates a new EntryPoint Object that is accepted by ModMenu
*
* @param target The delegate Object that will receive calls from ModMenu
* @return A Proxy that conforms to the ModMenu spec
*/
// public static ModMenuApi createEntrypoint(ModMenuIntegration target) {
// Class<?> iModMenuAPI;
// //Class<?> iModMenuAPIMarker = null;
// try { // try {
// iModMenuAPI = Class.forName("com.terraformersmc.modmenu.api.ModMenuApi"); // iConfigScreenFactory = Class.forName("com.terraformersmc.modmenu.api.ConfigScreenFactory");
// //iModMenuAPIMarker = Class.forName("com.terraformersmc.modmenu.util.ModMenuApiMarker");
// } catch (ClassNotFoundException e) { // } catch (ClassNotFoundException e) {
// e.printStackTrace(); // e.printStackTrace();
// return null; // return null;
@ -90,95 +37,148 @@ public abstract class ModMenuIntegration {
// //
// Object o = Proxy.newProxyInstance( // Object o = Proxy.newProxyInstance(
// ModMenuIntegration.class.getClassLoader(), // ModMenuIntegration.class.getClassLoader(),
// new Class[]{iModMenuAPI}, // new Class[]{iConfigScreenFactory, ModMenuScreenFactory.class},
// new BCLibModMenuInvocationHandler(target) // new ScreenFactoryInvocationHandler(act)
// ); // );
// //
// return (ModMenuApi) o; // return (ModMenuScreenFactory) o;
// } // }
//}
/** //
* The factory passed to {@link #ModMenuIntegration(ModMenuScreenFactory)} //@Deprecated
*/ ///**
protected final ModMenuScreenFactory screenFactory; // * Integration, to provide a custom Screen for ModMenu.
// * <p>
/** // * This integration allows you to use ModMenu without adding a dependency to your project. If the
* Create a new ModMenu delegate // * Mod is installed on the Client, and the correct ModMenu-EntryPoint is registered in your <i>fabric.mod.json</i>
* // * the screen will show up.
* @param screenFactory A Factory. The Factory receives the currently visible {@code parent}-Screen // * <p>
* and must return a new Screen Object. // * You only need to subclass this class, and initialize a static Field of Type {@link ModMenuApi} using
*/ // * the {@link #createEntrypoint(ModMenuIntegration)}-Method.
public ModMenuIntegration(ModMenuScreenFactory screenFactory) { // * <p>
this.screenFactory = screenFactory; // * Example:
} // * <pre>{@code public class ModMenu extends ModMenuIntegration {
// * public static final ModMenuApiMarker entrypointObject = createEntrypoint(new EntryPoint());
/** // *
* A Helper class to make a BCLib-Factory conform to the ModMenu-Factory Interface. // * public EntryPoint() {
* // * super(GridScreen::new);
* @param factory A BCLib-Type Factory, ie. {@code GridScreen::new } // * }
* @return A ModMenu Factory for a Screen // * }}</pre>
*/ // * You'd also need to add the ModMenu-Entrypoint to your <i>fabric.mod.json</i>:
final protected ModMenuScreenFactory createFactory(ModMenuScreenFactory factory) { // * <pre>"entrypoints": {
return ModMenuScreenFactoryImpl.create(factory); // * ...
} // * "modmenu": [ "your.mod.ModMenu::entrypointObject" ]
// * }</pre>
/** // */
* Used to construct a new config screen instance when your mod's //public abstract class ModMenuIntegration {
* configuration button is selected on the mod menu screen. The // /**
* screen instance parameter is the active mod menu screen. // * Creates a new EntryPoint Object that is accepted by ModMenu
* (Text copied from ModMenu) // *
* // * @param target The delegate Object that will receive calls from ModMenu
* @return A factory for constructing config screen instances. // * @return A Proxy that conforms to the ModMenu spec
*/ // */
public ModMenuScreenFactory getModConfigScreenFactory() { //// public static ModMenuApi createEntrypoint(ModMenuIntegration target) {
return createFactory(screenFactory); //// Class<?> iModMenuAPI;
} //// //Class<?> iModMenuAPIMarker = null;
//// try {
/** //// iModMenuAPI = Class.forName("com.terraformersmc.modmenu.api.ModMenuApi");
* Used to provide config screen factories for other mods. This takes second //// //iModMenuAPIMarker = Class.forName("com.terraformersmc.modmenu.util.ModMenuApiMarker");
* priority to a mod's own config screen factory provider. For example, if //// } catch (ClassNotFoundException e) {
* mod `xyz` supplies a config screen factory, mod `abc` providing a config //// e.printStackTrace();
* screen to `xyz` will be pointless, as the one provided by `xyz` will be //// return null;
* used. //// }
* <p> ////
* This method is NOT meant to be used to add a config screen factory to //// Object o = Proxy.newProxyInstance(
* your own mod. //// ModMenuIntegration.class.getClassLoader(),
* (Text copied from ModMenu) //// new Class[]{iModMenuAPI},
* //// new BCLibModMenuInvocationHandler(target)
* @return a map of mod ids to screen factories. //// );
*/ ////
public Map<String, ModMenuScreenFactory> getProvidedConfigScreenFactories() { //// return (ModMenuApi) o;
return ImmutableMap.of(); //// }
} //
// /**
@Override // * The factory passed to {@link #ModMenuIntegration(ModMenuScreenFactory)}
public String toString() { // */
return super.toString(); // protected final ModMenuScreenFactory screenFactory;
} //
// /**
/** // * Create a new ModMenu delegate
* A Factory Interface for ModMenu-Screens // *
* <p> // * @param screenFactory A Factory. The Factory receives the currently visible {@code parent}-Screen
* The Interface matches {@code com.terraformersmc.modmenu.api.ConfigScreenFactory} // * and must return a new Screen Object.
*/ // */
@FunctionalInterface // public ModMenuIntegration(ModMenuScreenFactory screenFactory) {
public interface ModMenuScreenFactory<S extends Screen>/*extends ConfigScreenFactory*/ { // this.screenFactory = screenFactory;
S create(Screen parent); // }
} //
// /**
record BCLibModMenuInvocationHandler(ModMenuIntegration target) implements InvocationHandler { // * A Helper class to make a BCLib-Factory conform to the ModMenu-Factory Interface.
@Override // *
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // * @param factory A BCLib-Type Factory, ie. {@code GridScreen::new }
// return switch (method.getName()) { // * @return A ModMenu Factory for a Screen
// case "getModConfigScreenFactory" -> target.getModConfigScreenFactory(); // */
// case "getProvidedConfigScreenFactories" -> target.getProvidedConfigScreenFactories(); // final protected ModMenuScreenFactory createFactory(ModMenuScreenFactory factory) {
// case "toString" -> target.toString(); // return ModMenuScreenFactoryImpl.create(factory);
// case "equals" -> target.equals(args[0]); // }
// case "hashCode" -> target.hashCode(); //
// default -> null; // /**
// }; // * Used to construct a new config screen instance when your mod's
return null; // * configuration button is selected on the mod menu screen. The
} // * screen instance parameter is the active mod menu screen.
} // * (Text copied from ModMenu)
// *
} // * @return A factory for constructing config screen instances.
// */
// public ModMenuScreenFactory getModConfigScreenFactory() {
// return createFactory(screenFactory);
// }
//
// /**
// * Used to provide config screen factories for other mods. This takes second
// * priority to a mod's own config screen factory provider. For example, if
// * mod `xyz` supplies a config screen factory, mod `abc` providing a config
// * screen to `xyz` will be pointless, as the one provided by `xyz` will be
// * used.
// * <p>
// * This method is NOT meant to be used to add a config screen factory to
// * your own mod.
// * (Text copied from ModMenu)
// *
// * @return a map of mod ids to screen factories.
// */
// public Map<String, ModMenuScreenFactory> getProvidedConfigScreenFactories() {
// return ImmutableMap.of();
// }
//
// @Override
// public String toString() {
// return super.toString();
// }
//
// /**
// * A Factory Interface for ModMenu-Screens
// * <p>
// * The Interface matches {@code com.terraformersmc.modmenu.api.ConfigScreenFactory}
// */
// @FunctionalInterface
// public interface ModMenuScreenFactory<S extends Screen>/*extends ConfigScreenFactory*/ {
// S create(Screen parent);
// }
//
// record BCLibModMenuInvocationHandler(ModMenuIntegration target) implements InvocationHandler {
// @Override
// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//// return switch (method.getName()) {
//// case "getModConfigScreenFactory" -> target.getModConfigScreenFactory();
//// case "getProvidedConfigScreenFactories" -> target.getProvidedConfigScreenFactories();
//// case "toString" -> target.toString();
//// case "equals" -> target.equals(args[0]);
//// case "hashCode" -> target.hashCode();
//// default -> null;
//// };
// return null;
// }
// }
//
//}