Re-Enabled EMI

This commit is contained in:
Frank 2022-12-09 11:22:25 +01:00
parent 0cb4596037
commit 15765bf30a
5 changed files with 521 additions and 521 deletions

View file

@ -1,117 +1,117 @@
package org.betterx.bclib.integration.emi;
//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()));
// 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.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()));
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,110 +1,110 @@
package org.betterx.bclib.integration.emi;
//import org.betterx.bclib.BCLib;
//import org.betterx.bclib.recipes.AnvilRecipe;
//
//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()));
// 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.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()));
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,103 +1,103 @@
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 com.mojang.math.Matrix4f;
//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 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, false, 0, 0xF000F0);
// font.drawInBatch(content, xx, yy - 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
// font.drawInBatch(content, xx + 1, yy - 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
// font.drawInBatch(content, xx - 1, yy, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
// font.drawInBatch(content, xx + 1, yy, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
// font.drawInBatch(content, xx - 1, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
// font.drawInBatch(content, xx + 1, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
// font.drawInBatch(content, xx, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
//
// font.drawInBatch(content, xx, yy, 0xFFFFFFFF, true, matrix, bufferSource, false, 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, false, 0, 0xF000F0);
font.drawInBatch(content, xx, yy - 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
font.drawInBatch(content, xx + 1, yy - 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
font.drawInBatch(content, xx - 1, yy, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
font.drawInBatch(content, xx + 1, yy, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
font.drawInBatch(content, xx - 1, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
font.drawInBatch(content, xx + 1, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
font.drawInBatch(content, xx, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0);
font.drawInBatch(content, xx, yy, 0xFFFFFFFF, true, matrix, bufferSource, false, 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];
}
}