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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,30 +1,30 @@
package org.betterx.bclib.integration.modmenu;
import net.minecraft.client.gui.screens.Screen;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
/**
* 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.
* <p>
* You can add a screen for your mod by calling {@link #addModMenuScreen(String, Function)}
*/
public class ModMenu {
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));}
*
* @param modID The ID of your Mod
* @param scr a function that takes a parent {@link Screen} and provides the main Screen you want
* to show with ModMenu for your Mod.
*/
public static void addModMenuScreen(String modID, Function<Screen, Screen> scr) {
screen.put(modID, scr);
}
}
//import net.minecraft.client.gui.screens.Screen;
//
//import java.util.HashMap;
//import java.util.Map;
//import java.util.function.Function;
//
///**
// * 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.
// * <p>
// * You can add a screen for your mod by calling {@link #addModMenuScreen(String, Function)}
// */
//public class ModMenu {
// 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));}
// *
// * @param modID The ID of your Mod
// * @param scr a function that takes a parent {@link Screen} and provides the main Screen you want
// * to show with ModMenu for your Mod.
// */
// public static void addModMenuScreen(String modID, Function<Screen, Screen> scr) {
// screen.put(modID, scr);
// }
//}

View file

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

View file

@ -1,88 +1,35 @@
package org.betterx.bclib.integration.modmenu;
import org.betterx.bclib.integration.modmenu.ModMenuIntegration.ModMenuScreenFactory;
import net.minecraft.client.gui.screens.Screen;
import com.google.common.collect.ImmutableMap;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
@Deprecated
class ModMenuScreenFactoryImpl {
record ScreenFactoryInvocationHandler(ModMenuScreenFactory act) implements InvocationHandler {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// return switch (method.getName()) {
// case "toString" -> "";
// case "equals" -> false;
// case "hashCode" -> 0;
// default -> act.create((Screen) args[0]);
// };
return null;
}
}
public static ModMenuScreenFactory create(ModMenuScreenFactory act) {
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;
//import org.betterx.bclib.integration.modmenu.ModMenuIntegration.ModMenuScreenFactory;
//
//import net.minecraft.client.gui.screens.Screen;
//
//import com.google.common.collect.ImmutableMap;
//
//import java.lang.reflect.InvocationHandler;
//import java.lang.reflect.Method;
//import java.lang.reflect.Proxy;
//import java.util.Map;
//
//@Deprecated
//class ModMenuScreenFactoryImpl {
// record ScreenFactoryInvocationHandler(ModMenuScreenFactory act) implements InvocationHandler {
// @Override
// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//// return switch (method.getName()) {
//// case "toString" -> "";
//// case "equals" -> false;
//// case "hashCode" -> 0;
//// default -> act.create((Screen) args[0]);
//// };
// return null;
// }
// }
//
// public static ModMenuScreenFactory create(ModMenuScreenFactory act) {
// Class<?> iConfigScreenFactory = null;
// try {
// iModMenuAPI = Class.forName("com.terraformersmc.modmenu.api.ModMenuApi");
// //iModMenuAPIMarker = Class.forName("com.terraformersmc.modmenu.util.ModMenuApiMarker");
// iConfigScreenFactory = Class.forName("com.terraformersmc.modmenu.api.ConfigScreenFactory");
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// return null;
@ -90,95 +37,148 @@ public abstract class ModMenuIntegration {
//
// Object o = Proxy.newProxyInstance(
// ModMenuIntegration.class.getClassLoader(),
// new Class[]{iModMenuAPI},
// new BCLibModMenuInvocationHandler(target)
// new Class[]{iConfigScreenFactory, ModMenuScreenFactory.class},
// new ScreenFactoryInvocationHandler(act)
// );
//
// return (ModMenuApi) o;
// return (ModMenuScreenFactory) o;
// }
/**
* The factory passed to {@link #ModMenuIntegration(ModMenuScreenFactory)}
*/
protected final ModMenuScreenFactory screenFactory;
/**
* Create a new ModMenu delegate
*
* @param screenFactory A Factory. The Factory receives the currently visible {@code parent}-Screen
* and must return a new Screen Object.
*/
public ModMenuIntegration(ModMenuScreenFactory screenFactory) {
this.screenFactory = screenFactory;
}
/**
* A Helper class to make a BCLib-Factory conform to the ModMenu-Factory Interface.
*
* @param factory A BCLib-Type Factory, ie. {@code GridScreen::new }
* @return A ModMenu Factory for a Screen
*/
final protected ModMenuScreenFactory createFactory(ModMenuScreenFactory factory) {
return ModMenuScreenFactoryImpl.create(factory);
}
/**
* Used to construct a new config screen instance when your mod's
* 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;
}
}
}
//}
//
//@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 {
//// iModMenuAPI = Class.forName("com.terraformersmc.modmenu.api.ModMenuApi");
//// //iModMenuAPIMarker = Class.forName("com.terraformersmc.modmenu.util.ModMenuApiMarker");
//// } catch (ClassNotFoundException e) {
//// e.printStackTrace();
//// return null;
//// }
////
//// Object o = Proxy.newProxyInstance(
//// ModMenuIntegration.class.getClassLoader(),
//// new Class[]{iModMenuAPI},
//// new BCLibModMenuInvocationHandler(target)
//// );
////
//// return (ModMenuApi) o;
//// }
//
// /**
// * The factory passed to {@link #ModMenuIntegration(ModMenuScreenFactory)}
// */
// protected final ModMenuScreenFactory screenFactory;
//
// /**
// * Create a new ModMenu delegate
// *
// * @param screenFactory A Factory. The Factory receives the currently visible {@code parent}-Screen
// * and must return a new Screen Object.
// */
// public ModMenuIntegration(ModMenuScreenFactory screenFactory) {
// this.screenFactory = screenFactory;
// }
//
// /**
// * A Helper class to make a BCLib-Factory conform to the ModMenu-Factory Interface.
// *
// * @param factory A BCLib-Type Factory, ie. {@code GridScreen::new }
// * @return A ModMenu Factory for a Screen
// */
// final protected ModMenuScreenFactory createFactory(ModMenuScreenFactory factory) {
// return ModMenuScreenFactoryImpl.create(factory);
// }
//
// /**
// * Used to construct a new config screen instance when your mod's
// * 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;
// }
// }
//
//}