This commit is contained in:
Flanks255 2024-07-27 17:51:54 -05:00
parent d0b7e95ed5
commit 0c493b9169
3 changed files with 28 additions and 24 deletions

View file

@ -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);

View file

@ -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<CrushingRecipe> CRUSHING = RecipeType.create(ActuallyAdditions.MODID, "crushing", CrushingRecipe.class);
public static final RecipeType<MiningLensRecipe> 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) {

View file

@ -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<IItemHandler> getItemHandler(ItemStack stack) {
return Optional.ofNullable(stack.getCapability(Capabilities.ItemHandler.ITEM));
}
@Nonnull
public static Optional<IEnergyStorage> getEnergyStorage(@Nonnull ItemStack stack) {
return Optional.ofNullable(stack.getCapability(Capabilities.EnergyStorage.ITEM));
}
}