-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/jackyy/simplesponge/integration/JEIPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package jackyy.simplesponge.integration; | ||
|
||
import jackyy.simplesponge.SimpleSponge; | ||
import jackyy.simplesponge.registry.ModItems; | ||
import mezz.jei.api.IModPlugin; | ||
import mezz.jei.api.JeiPlugin; | ||
import mezz.jei.api.constants.VanillaTypes; | ||
import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter; | ||
import mezz.jei.api.ingredients.subtypes.UidContext; | ||
import mezz.jei.api.registration.ISubtypeRegistration; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.common.capabilities.ForgeCapabilities; | ||
import net.minecraftforge.energy.IEnergyStorage; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
import java.util.Optional; | ||
|
||
@JeiPlugin | ||
public class JEIPlugin implements IModPlugin { | ||
|
||
@Override | ||
public ResourceLocation getPluginUid() { | ||
return new ResourceLocation(SimpleSponge.MODID, "jei_plugin"); | ||
} | ||
|
||
@Override | ||
public void registerItemSubtypes(ISubtypeRegistration registration) { | ||
for (RegistryObject<Item> item : ModItems.ITEMS.getEntries()) { | ||
ItemStack stack = item.get().getDefaultInstance(); | ||
if (stack.getCapability(ForgeCapabilities.ENERGY).isPresent()) { | ||
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, item.get(), INTERPRETER); | ||
} | ||
} | ||
} | ||
|
||
private static final IIngredientSubtypeInterpreter<ItemStack> INTERPRETER = (stack, context) -> { | ||
if (context == UidContext.Ingredient && stack.hasTag()) { | ||
Optional<IEnergyStorage> capability = stack.getCapability(ForgeCapabilities.ENERGY).resolve(); | ||
if (capability.isPresent()) { | ||
IEnergyStorage energyStorage = capability.get(); | ||
String subtype; | ||
if (energyStorage.getEnergyStored() == energyStorage.getMaxEnergyStored()) { | ||
subtype = "filled"; | ||
} else { | ||
subtype = "empty"; | ||
} | ||
return subtype; | ||
} | ||
} | ||
return IIngredientSubtypeInterpreter.NONE; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters