From 0c493b9169fdce60fe707b03c2a7cdc93597998c Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Sat, 27 Jul 2024 17:51:54 -0500 Subject: [PATCH] Things --- .../actuallyadditions/mod/ActuallyTabs.java | 6 +-- .../mod/jei/JEIActuallyAdditionsPlugin.java | 40 ++++++++++--------- .../actuallyadditions/mod/util/CapHelper.java | 6 +++ 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java index 42715df97..4aece2ff2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java @@ -3,7 +3,6 @@ package de.ellpeck.actuallyadditions.mod; import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; -import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; @@ -31,10 +30,7 @@ public class ActuallyTabs { .filter(stack -> stack.getItem() instanceof ItemEnergy).toList(); charged.forEach(stack -> { if(stack.getItem() instanceof ItemEnergy itemEnergy) { - CustomEnergyStorage storage = new CustomEnergyStorage(itemEnergy.maxPower, itemEnergy.transfer, itemEnergy.transfer); - storage.setEnergyStored(itemEnergy.maxPower); - stack.set(ActuallyComponents.ENERGY_STORAGE.get(), storage); - stack.getOrCreateTag().putBoolean("Charged", true); + stack.set(ActuallyComponents.ENERGY_STORAGE.get(), itemEnergy.maxPower); //TODO dunno if this works } }); stacks.addAll(charged); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java index 55bb451d3..074d43c21 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/JEIActuallyAdditionsPlugin.java @@ -12,18 +12,12 @@ package de.ellpeck.actuallyadditions.mod.jei; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; -import de.ellpeck.actuallyadditions.mod.crafting.ActuallyRecipes; -import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe; -import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe; -import de.ellpeck.actuallyadditions.mod.crafting.EmpowererRecipe; -import de.ellpeck.actuallyadditions.mod.crafting.FermentingRecipe; -import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe; -import de.ellpeck.actuallyadditions.mod.crafting.MiningLensRecipe; -import de.ellpeck.actuallyadditions.mod.crafting.PressingRecipe; +import de.ellpeck.actuallyadditions.mod.crafting.*; import de.ellpeck.actuallyadditions.mod.inventory.gui.CrusherScreen; import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiCoffeeMachine; import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiFurnaceDouble; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; +import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.jei.coffee.CoffeeMachineCategory; import de.ellpeck.actuallyadditions.mod.jei.crusher.CrusherCategory; import de.ellpeck.actuallyadditions.mod.jei.empowerer.EmpowererRecipeCategory; @@ -31,21 +25,22 @@ import de.ellpeck.actuallyadditions.mod.jei.fermenting.FermentingCategory; import de.ellpeck.actuallyadditions.mod.jei.laser.LaserRecipeCategory; import de.ellpeck.actuallyadditions.mod.jei.lens.MiningLensRecipeCategory; import de.ellpeck.actuallyadditions.mod.jei.pressing.PressingCategory; +import de.ellpeck.actuallyadditions.mod.util.CapHelper; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; import mezz.jei.api.constants.RecipeTypes; import mezz.jei.api.helpers.IJeiHelpers; import mezz.jei.api.recipe.RecipeType; -import mezz.jei.api.registration.IGuiHandlerRegistration; -import mezz.jei.api.registration.IRecipeCatalystRegistration; -import mezz.jei.api.registration.IRecipeCategoryRegistration; -import mezz.jei.api.registration.IRecipeRegistration; +import mezz.jei.api.registration.*; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; +import javax.annotation.Nonnull; +import java.util.Optional; + @JeiPlugin public class JEIActuallyAdditionsPlugin implements IModPlugin { public static final ResourceLocation ID = ActuallyAdditions.modLoc("jei_plugin"); @@ -62,13 +57,20 @@ public class JEIActuallyAdditionsPlugin implements IModPlugin { public static final RecipeType CRUSHING = RecipeType.create(ActuallyAdditions.MODID, "crushing", CrushingRecipe.class); public static final RecipeType MINING_LENS = RecipeType.create(ActuallyAdditions.MODID, "mining_lens", MiningLensRecipe.class); -// @Override TODO: See if this is still needed -// public void registerItemSubtypes(@Nonnull ISubtypeRegistration reg) { -// ActuallyItems.ITEMS.getEntries().forEach(entry -> { -// if (entry.get() instanceof ItemEnergy) -// reg.useNbtForSubtypes(entry.get()); -// }); -// } + @Override + public void registerItemSubtypes(@Nonnull ISubtypeRegistration reg) { + ActuallyItems.ITEMS.getEntries().forEach(entry -> { + if (entry.get() instanceof ItemEnergy) + reg.registerSubtypeInterpreter(entry.get(), + (ingredient, context) -> CapHelper.getEnergyStorage(ingredient).flatMap(storage -> { + if (storage.getEnergyStored() == storage.getMaxEnergyStored()) { + return Optional.of("charged"); + } else { + return Optional.of("uncharged"); + } + }).orElse("uncharged")); + }); + } @Override public void registerCategories(IRecipeCategoryRegistration registry) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/CapHelper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/CapHelper.java index f860355b0..0fb51c2b7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/CapHelper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/CapHelper.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.items.IItemHandler; import javax.annotation.Nonnull; @@ -30,4 +31,9 @@ public class CapHelper { public static Optional getItemHandler(ItemStack stack) { return Optional.ofNullable(stack.getCapability(Capabilities.ItemHandler.ITEM)); } + + @Nonnull + public static Optional getEnergyStorage(@Nonnull ItemStack stack) { + return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM)); + } }