From fd2559e0381d27515eb7afc5efa5cd3374483777 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 9 Dec 2022 12:37:02 +0100 Subject: [PATCH] [Changes] Removed JEI integration --- .../integration/jei/JEIAlloyingCategory.java | 171 ---------------- .../jei/JEIAlloyingFuelCategory.java | 183 ------------------ .../betterend/integration/jei/JEIPlugin.java | 71 ------- src/main/resources/fabric.mod.json | 3 - 4 files changed, 428 deletions(-) delete mode 100644 src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingCategory.java delete mode 100644 src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingFuelCategory.java delete mode 100644 src/main/java/org/betterx/betterend/integration/jei/JEIPlugin.java diff --git a/src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingCategory.java b/src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingCategory.java deleted file mode 100644 index 649f23e1..00000000 --- a/src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingCategory.java +++ /dev/null @@ -1,171 +0,0 @@ -package org.betterx.betterend.integration.jei; - -import org.betterx.bclib.recipes.AlloyingRecipe; -import org.betterx.betterend.BetterEnd; -import org.betterx.betterend.registry.EndBlocks; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import mezz.jei.api.constants.ModIds; -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; -import mezz.jei.api.gui.drawable.IDrawableStatic; -import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; - -public class JEIAlloyingCategory implements IRecipeCategory { - public static final RecipeType TYPE = RecipeType.create( - BetterEnd.MOD_ID, - AlloyingRecipe.GROUP, - AlloyingRecipe.class - ); - public static final String TEXTURE_GUI_PATH = "textures/gui/"; - public static final String TEXTURE_GUI_VANILLA = TEXTURE_GUI_PATH + "gui_vanilla.png"; - public static final ResourceLocation RECIPE_GUI_VANILLA = new ResourceLocation(ModIds.JEI_ID, TEXTURE_GUI_VANILLA); - public static final int width = 116; - public static final int height = 54; - - protected final IDrawableStatic staticFlame; - protected final IDrawableStatic addonSlot; - protected final IDrawableAnimated animatedFlame; - - private final IDrawable background; - private final IDrawable icon; - private final Component title; - private final LoadingCache cachedArrows; - - public JEIAlloyingCategory(IGuiHelper guiHelper) { - staticFlame = guiHelper.createDrawable(RECIPE_GUI_VANILLA, 82, 114, 14, 14); - animatedFlame = guiHelper.createAnimatedDrawable(staticFlame, 300, IDrawableAnimated.StartDirection.TOP, true); - background = guiHelper.createDrawable(RECIPE_GUI_VANILLA, 0, 114, 82, 54); - title = Component.translatable(EndBlocks.END_STONE_SMELTER.getDescriptionId()); - icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(EndBlocks.END_STONE_SMELTER)); - this.cachedArrows = CacheBuilder.newBuilder() - .maximumSize(25) - .build(new CacheLoader<>() { - @Override - public IDrawableAnimated load(Integer cookTime) { - return guiHelper.drawableBuilder( - RECIPE_GUI_VANILLA, - 82, - 128, - 24, - 17 - ) - .buildAnimated( - cookTime, - IDrawableAnimated.StartDirection.LEFT, - false - ); - } - }); - - addonSlot = guiHelper.getSlotDrawable(); - } - - protected IDrawableAnimated getArrow(AlloyingRecipe recipe) { - int cookTime = recipe.getSmeltTime(); - if (cookTime <= 0) { - cookTime = 0; - } - return this.cachedArrows.getUnchecked(cookTime); - } - - @Override - public RecipeType getRecipeType() { - return TYPE; - } - - @Override - public Component getTitle() { - return title; - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public void setRecipe(IRecipeLayoutBuilder builder, AlloyingRecipe recipe, IFocusGroup focuses) { - builder.addSlot(RecipeIngredientRole.INPUT, 1, 1) - .addIngredients(recipe.getIngredients().get(0)); - - if (recipe.getIngredients().size() > 1) { - builder.addSlot(RecipeIngredientRole.INPUT, 21, 1) - .addIngredients(recipe.getIngredients().get(1)); - } - - builder.addSlot(RecipeIngredientRole.OUTPUT, 61, 19) - .addItemStack(recipe.getResultItem()); - } - - @Override - public boolean isHandled(AlloyingRecipe recipe) { - return !recipe.isSpecial(); - } - - @Override - public void draw( - AlloyingRecipe recipe, - IRecipeSlotsView recipeSlotsView, - PoseStack poseStack, - double mouseX, - double mouseY - ) { - animatedFlame.draw(poseStack, 1, 20); - - if (recipe.getIngredients().size() > 1) { - addonSlot.draw(poseStack, 20, 0); - } - - IDrawableAnimated arrow = getArrow(recipe); - arrow.draw(poseStack, 24, 18); - - drawExperience(recipe, poseStack, 0); - drawCookTime(recipe, poseStack, 45); - - } - - protected void drawExperience(AlloyingRecipe recipe, PoseStack poseStack, int y) { - float experience = recipe.getExperience(); - if (experience > 0) { - Component experienceString = Component.translatable("gui.jei.category.smelting.experience", experience); - Minecraft minecraft = Minecraft.getInstance(); - Font fontRenderer = minecraft.font; - int stringWidth = fontRenderer.width(experienceString); - fontRenderer.draw(poseStack, experienceString, background.getWidth() - stringWidth, y, 0xFF808080); - } - } - - protected void drawCookTime(AlloyingRecipe recipe, PoseStack poseStack, int y) { - int cookTime = recipe.getSmeltTime(); - if (cookTime > 0) { - int cookTimeSeconds = cookTime / 20; - Component timeString = Component.translatable("gui.jei.category.smelting.time.seconds", cookTimeSeconds); - Minecraft minecraft = Minecraft.getInstance(); - net.minecraft.client.gui.Font fontRenderer = minecraft.font; - int stringWidth = fontRenderer.width(timeString); - fontRenderer.draw(poseStack, timeString, background.getWidth() - stringWidth, y, 0xFF808080); - } - } -} diff --git a/src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingFuelCategory.java b/src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingFuelCategory.java deleted file mode 100644 index bd1fc99a..00000000 --- a/src/main/java/org/betterx/betterend/integration/jei/JEIAlloyingFuelCategory.java +++ /dev/null @@ -1,183 +0,0 @@ -package org.betterx.betterend.integration.jei; - -import org.betterx.bclib.recipes.AlloyingRecipe; -import org.betterx.betterend.BetterEnd; -import org.betterx.betterend.blocks.entities.EndStoneSmelterBlockEntity; -import org.betterx.betterend.registry.EndBlocks; -import org.betterx.ui.layout.values.Rectangle; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.network.chat.Component; -import net.minecraft.world.item.ItemStack; - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import mezz.jei.api.constants.VanillaTypes; -import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; -import mezz.jei.api.gui.drawable.IDrawableStatic; -import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.recipe.IFocusGroup; -import mezz.jei.api.recipe.RecipeIngredientRole; -import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.recipe.category.IRecipeCategory; -import mezz.jei.api.recipe.vanilla.IJeiFuelingRecipe; -import mezz.jei.api.runtime.IIngredientManager; - -import java.text.NumberFormat; -import java.util.Comparator; -import java.util.List; -import org.jetbrains.annotations.Unmodifiable; - - -public class JEIAlloyingFuelCategory implements IRecipeCategory { - public static final RecipeType FUEL_TYPE = RecipeType.create( - BetterEnd.MOD_ID, - AlloyingRecipe.GROUP + "_fuel", - IJeiFuelingRecipe.class - ); - - private final IDrawableStatic background; - private final IDrawable icon; - private final Component localizedName; - private final LoadingCache cachedFlames; - private final Rectangle textArea; - - public static List getFuelRecipes(IIngredientManager ingredientManager) { - return ingredientManager.getAllIngredients(VanillaTypes.ITEM_STACK).stream() - .mapMulti((stack, consumer) -> { - if (EndStoneSmelterBlockEntity.canUseAsFuel(stack)) { - final int time = EndStoneSmelterBlockEntity.getFuelTime(stack); - if (time > 0) { - final List inputs = List.of(stack); - consumer.accept(new IJeiFuelingRecipe() { - @Override - public @Unmodifiable List getInputs() { - return inputs; - } - - @Override - public int getBurnTime() { - return time; - } - }); - } - } - - }) - .sorted(Comparator.comparingInt(IJeiFuelingRecipe::getBurnTime)) - .toList(); - } - - public JEIAlloyingFuelCategory(IGuiHelper guiHelper) { - - // width of the recipe depends on the text, which is different in each language - Minecraft minecraft = Minecraft.getInstance(); - Font fontRenderer = minecraft.font; - Component maxSmeltCountText = createSmeltCountText(10000000 * 200); - int maxStringWidth = fontRenderer.width(maxSmeltCountText.getString()); - int backgroundHeight = 34; - int textPadding = 20; - - background = guiHelper.drawableBuilder(JEIAlloyingCategory.RECIPE_GUI_VANILLA, 0, 134, 18, backgroundHeight) - .addPadding(0, 0, 0, textPadding + maxStringWidth) - .build(); - - textArea = new Rectangle(20, 0, textPadding + maxStringWidth, backgroundHeight); - - icon = guiHelper.createDrawableIngredient( - VanillaTypes.ITEM_STACK, - new ItemStack(EndBlocks.END_STONE_SMELTER) - ); - ; - localizedName = Component.translatable("gui.jei.category.fuel"); - - this.cachedFlames = CacheBuilder.newBuilder() - .maximumSize(25) - .build(new CacheLoader<>() { - @Override - public IDrawableAnimated load(Integer burnTime) { - return guiHelper.drawableBuilder( - JEIAlloyingCategory.RECIPE_GUI_VANILLA, - 82, - 114, - 14, - 14 - ) - .buildAnimated( - burnTime, - IDrawableAnimated.StartDirection.TOP, - true - ); - } - }); - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - public RecipeType getRecipeType() { - return FUEL_TYPE; - } - - @Override - public Component getTitle() { - return localizedName; - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public void setRecipe(IRecipeLayoutBuilder builder, IJeiFuelingRecipe recipe, IFocusGroup focuses) { - builder.addSlot(RecipeIngredientRole.INPUT, 1, 17) - .addItemStacks(recipe.getInputs()); - } - - @Override - public void draw( - IJeiFuelingRecipe recipe, - IRecipeSlotsView recipeSlotsView, - PoseStack poseStack, - double mouseX, - double mouseY - ) { - int burnTime = recipe.getBurnTime(); - IDrawableAnimated flame = cachedFlames.getUnchecked(burnTime); - flame.draw(poseStack, 1, 0); - Minecraft minecraft = Minecraft.getInstance(); - Font font = minecraft.font; - Component smeltCountText = createSmeltCountText(burnTime); - int width = font.width(smeltCountText); - int height = font.lineHeight; - - font.draw( - poseStack, - smeltCountText, - this.textArea.left + (this.textArea.width - width) / 2, - this.textArea.top + (this.textArea.height - height) / 2 + 1, - 0xFF808080 - ); - } - - private static Component createSmeltCountText(int burnTime) { - if (burnTime == 200) { - return Component.translatable("gui.jei.category.fuel.smeltCount.single"); - } else { - NumberFormat numberInstance = NumberFormat.getNumberInstance(); - numberInstance.setMaximumFractionDigits(2); - String smeltCount = numberInstance.format(burnTime / 200f); - return Component.translatable("gui.jei.category.fuel.smeltCount", smeltCount); - } - } -} diff --git a/src/main/java/org/betterx/betterend/integration/jei/JEIPlugin.java b/src/main/java/org/betterx/betterend/integration/jei/JEIPlugin.java deleted file mode 100644 index 5d3fa929..00000000 --- a/src/main/java/org/betterx/betterend/integration/jei/JEIPlugin.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.betterx.betterend.integration.jei; - -import org.betterx.bclib.recipes.AlloyingRecipe; -import org.betterx.betterend.BetterEnd; -import org.betterx.betterend.registry.EndBlocks; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.item.ItemStack; - -import mezz.jei.api.IModPlugin; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.helpers.IJeiHelpers; -import mezz.jei.api.registration.IRecipeCatalystRegistration; -import mezz.jei.api.registration.IRecipeCategoryRegistration; -import mezz.jei.api.registration.IRecipeRegistration; -import mezz.jei.api.registration.IRecipeTransferRegistration; -import mezz.jei.api.runtime.IIngredientManager; - -public class JEIPlugin implements IModPlugin { - public final static ResourceLocation PLUGIN_ID = BetterEnd.makeID("jei_plugin"); - - - @Override - public ResourceLocation getPluginUid() { - return PLUGIN_ID; - } - - @Override - public void registerCategories(IRecipeCategoryRegistration registration) { - IModPlugin.super.registerCategories(registration); - - IJeiHelpers jeiHelpers = registration.getJeiHelpers(); - IGuiHelper guiHelper = jeiHelpers.getGuiHelper(); - - registration.addRecipeCategories(new JEIAlloyingCategory(guiHelper)); - registration.addRecipeCategories(new JEIAlloyingFuelCategory(guiHelper)); - } - - @Override - public void registerRecipes(IRecipeRegistration registration) { - Minecraft minecraft = Minecraft.getInstance(); - ClientLevel world = minecraft.level; - var recipeManager = world.getRecipeManager(); - IIngredientManager ingredientManager = registration.getIngredientManager(); - - IModPlugin.super.registerRecipes(registration); - registration.addRecipes(JEIAlloyingCategory.TYPE, recipeManager.getAllRecipesFor(AlloyingRecipe.TYPE)); - registration.addRecipes( - JEIAlloyingFuelCategory.FUEL_TYPE, - JEIAlloyingFuelCategory.getFuelRecipes(ingredientManager) - ); - } - - @Override - public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { - IModPlugin.super.registerRecipeCatalysts(registration); - registration.addRecipeCatalyst( - new ItemStack(EndBlocks.END_STONE_SMELTER), - JEIAlloyingCategory.TYPE, - JEIAlloyingFuelCategory.FUEL_TYPE - ); - } - - @Override - public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { - IModPlugin.super.registerRecipeTransferHandlers(registration); - - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 80765d4a..426985cb 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -31,9 +31,6 @@ "rei_client": [ "org.betterx.betterend.integration.rei.REIPlugin" ], - "jei_mod_plugin": [ - "org.betterx.betterend.integration.jei.JEIPlugin" - ], "emi": [ "org.betterx.betterend.integration.emi.EMIPlugin" ]