From 1780be4fc967ab30e06b1e625ee707a3de5fdb6b Mon Sep 17 00:00:00 2001 From: deirn Date: Fri, 26 Jul 2024 23:51:18 +0700 Subject: [PATCH] mekanism: basics --- .../main/kotlin/FetchLatestVersionsTask.kt | 4 +- dependencies.json | 16 +- modules/forge/mekanism/build.gradle.kts | 12 +- .../module/mekanism/MeganeMekaninsm.java | 30 ++++ .../mekanism/mixin/AccessLookingAtUtils.java | 54 +++++++ .../mixin/MixinMekanismWTHITPlugin.java | 25 +++ .../mekanism/provider/ChemicalProvider.java | 148 ++++++++++++++++++ .../mekanism/provider/FluidProvider.java | 55 +++++++ .../mekanism/provider/MultiblockProvider.java | 39 +++++ .../provider/StrictEnergyProvider.java | 33 ++++ settings.gradle.kts | 2 +- 11 files changed, 405 insertions(+), 13 deletions(-) create mode 100644 modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/AccessLookingAtUtils.java create mode 100644 modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/MixinMekanismWTHITPlugin.java create mode 100644 modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/ChemicalProvider.java create mode 100644 modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/FluidProvider.java create mode 100644 modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/MultiblockProvider.java create mode 100644 modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/StrictEnergyProvider.java diff --git a/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt b/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt index 6052d5b..e0745bd 100644 --- a/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt +++ b/buildSrc/src/main/kotlin/FetchLatestVersionsTask.kt @@ -105,8 +105,8 @@ abstract class FetchLatestVersionsTask : DefaultTask() { } fetcher(ModrinthVersionFetcher, "forge", forge.mekanism) { - fetch(forge.mekanism::core, mrIds.mekCore) { "mekanism:Mekanism:1.20.1-${it.version_number}" } - fetch(forge.mekanism::generators, mrIds.mekCore) { "mekanism:Mekanism:1.20.1-${it.version_number}:generators" } + fetch(forge.mekanism::core, mrIds.mekCore) { "mekanism:Mekanism:${versions.minecraft}-${it.version_number}" } + fetch(forge.mekanism::generators, mrIds.mekCore) { "mekanism:Mekanism:${versions.minecraft}-${it.version_number}:generators" } } fetcher(ModrinthVersionFetcher, "forge", forge.thermal) { diff --git a/dependencies.json b/dependencies.json index ec0585c..41503ae 100644 --- a/dependencies.json +++ b/dependencies.json @@ -1,6 +1,6 @@ { - "fabric.wthit.api" : "mcp.mobius.waila:wthit-api:fabric-5.28.0", - "fabric.wthit.runtime" : "mcp.mobius.waila:wthit:fabric-5.28.0", + "fabric.wthit.api" : "mcp.mobius.waila:wthit-api:fabric-5.28.2", + "fabric.wthit.runtime" : "mcp.mobius.waila:wthit:fabric-5.28.2", "fabric.badpackets" : "lol.bai:badpackets:fabric-0.2.3", "fabric.ae2" : "appeng:appliedenergistics2-fabric:12.9.9", "fabric.alloyForge" : "maven.modrinth:jhl28YkY:q1L7hbA8", @@ -26,21 +26,21 @@ "fabric.wirelessNet" : "curse.maven:cursemod-461316:3876132", "fabric.lapisReserve" : "curse.maven:cursemod-399679:3345208", "fabric.resourceChickens" : "curse.api:632145:4985700", - "forge.wthit.api" : "mcp.mobius.waila:wthit-api:forge-5.28.0", - "forge.wthit.runtime" : "mcp.mobius.waila:wthit:forge-5.28.0", + "forge.wthit.api" : "mcp.mobius.waila:wthit-api:forge-5.28.2", + "forge.wthit.runtime" : "mcp.mobius.waila:wthit:forge-5.28.2", "forge.badpackets" : "lol.bai:badpackets:forge-0.2.3", "forge.ae2" : "appeng:appliedenergistics2-forge:12.9.9", "forge.create" : "maven.modrinth:LNytGWDc:Vfzp1Xaz", "forge.ie" : "maven.modrinth:tIm2nV03:VzTXQKEm", "forge.rs" : "maven.modrinth:KDvYkUg3:q3LiZwUb", - "forge.jei" : "maven.modrinth:u6dRKJwZ:2vJsVMlk", - "forge.mekanism.core" : "mekanism:Mekanism:1.20.1-10.3.9.13", - "forge.mekanism.generators" : "mekanism:Mekanism:1.20.1-10.3.9.13:generators", + "forge.jei" : "maven.modrinth:u6dRKJwZ:8HIXqeHh", + "forge.mekanism.core" : "mekanism:Mekanism:1.19.2-10.3.9.13", + "forge.mekanism.generators" : "mekanism:Mekanism:1.19.2-10.3.9.13:generators", "forge.thermal.cofhCore" : "maven.modrinth:OWSRM4vD:ssRHxD6e", "forge.thermal.foundation" : "maven.modrinth:Xvg6q5Wp:kaIOIjDc", "forge.thermal.expansion" : "maven.modrinth:hmD6rrUJ:W9opx6mY", "forge.lapisReserve" : "curse.maven:cursemod-399679:3787247", - "forge.resourceChickens" : "curse.api:632145:5088913", + "forge.resourceChickens" : "curse.api:632145:5512583", "forge.productiveBees" : "curse.maven:cursemod-377897:4566382", "forge.top" : "curse.maven:cursemod-245211:3965693" } \ No newline at end of file diff --git a/modules/forge/mekanism/build.gradle.kts b/modules/forge/mekanism/build.gradle.kts index 6c94056..6567e70 100644 --- a/modules/forge/mekanism/build.gradle.kts +++ b/modules/forge/mekanism/build.gradle.kts @@ -1,7 +1,16 @@ metadata("lol.bai.megane.module.mekanism") { - waila("MeganeMekaninsm") + waila("MeganeMekaninsm") { + required("mekanism") + } + + mixin { + callback(mixin::add, mixin::config) + require(forgeMod("mekanism")) + } + forgeFml() packMcmeta() + language() modsToml { depends( @@ -16,5 +25,4 @@ repositories { dependencies { implementation(fg.deobf(deps.forge.mekanism.core)) - implementation(fg.deobf(deps.forge.mekanism.generators)) } diff --git a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/MeganeMekaninsm.java b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/MeganeMekaninsm.java index 2dceb42..039a263 100644 --- a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/MeganeMekaninsm.java +++ b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/MeganeMekaninsm.java @@ -1,13 +1,43 @@ package lol.bai.megane.module.mekanism; +import lol.bai.megane.module.mekanism.provider.ChemicalProvider; +import lol.bai.megane.module.mekanism.provider.FluidProvider; +import lol.bai.megane.module.mekanism.provider.MultiblockProvider; +import lol.bai.megane.module.mekanism.provider.StrictEnergyProvider; import mcp.mobius.waila.api.IRegistrar; import mcp.mobius.waila.api.IWailaPlugin; +import mcp.mobius.waila.api.TooltipPosition; +import mcp.mobius.waila.api.data.EnergyData; +import mekanism.common.lib.multiblock.IMultiblockBase; +import mekanism.common.tile.base.TileEntityUpdateable; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.entity.BlockEntity; public class MeganeMekaninsm implements IWailaPlugin { + public static final ResourceLocation CONFIG_SHOW_CHEMICALS = id("chemical"); + + public static ResourceLocation id(String path) { + return new ResourceLocation("megane", "mekanism." + path); + } + @Override public void register(IRegistrar registrar) { + EnergyData.describe("mekanism").color(0x3CFE9A); + + registrar.addFeatureConfig(CONFIG_SHOW_CHEMICALS, false); + registrar.addDataType(ChemicalProvider.DATA, ChemicalProvider.Data.class, ChemicalProvider.Data::new); + registrar.addBlockData(new ChemicalProvider.Blocker(), BlockEntity.class, 0); + var chemicalProvider = new ChemicalProvider(); + registrar.addBlockData(chemicalProvider, BlockEntity.class, 1500); + registrar.addComponent(chemicalProvider, TooltipPosition.BODY, BlockEntity.class, 600); + + registrar.addBlockData(new StrictEnergyProvider(), BlockEntity.class, 1500); + + var fluidProvider = new FluidProvider(); + registrar.addBlockData(fluidProvider, TileEntityUpdateable.class); + registrar.addBlockData(new MultiblockProvider(fluidProvider), IMultiblockBase.class, 900); } } diff --git a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/AccessLookingAtUtils.java b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/AccessLookingAtUtils.java new file mode 100644 index 0000000..4fe5a1c --- /dev/null +++ b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/AccessLookingAtUtils.java @@ -0,0 +1,54 @@ +package lol.bai.megane.module.mekanism.mixin; + +import java.util.List; +import java.util.function.Function; + +import mekanism.api.chemical.Chemical; +import mekanism.api.chemical.ChemicalStack; +import mekanism.api.chemical.IChemicalHandler; +import mekanism.api.chemical.IChemicalTank; +import mekanism.api.chemical.merged.MergedChemicalTank; +import mekanism.api.text.ILangEntry; +import mekanism.common.capabilities.merged.MergedTank; +import mekanism.common.integration.lookingat.LookingAtHelper; +import mekanism.common.integration.lookingat.LookingAtUtils; +import mekanism.common.lib.multiblock.MultiblockData; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fluids.capability.IFluidHandler; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(LookingAtUtils.class) +public interface AccessLookingAtUtils { + + @Invoker("getMultiblock") + static @Nullable MultiblockData megane_getMultiblock(BlockEntity tile) { + throw new AssertionError("mixin"); + } + + @Invoker("displayFluid") + static void megane_displayFluid(LookingAtHelper info, IFluidHandler fluidHandler) { + + } + + @Invoker("addInfo") + static < + CHEMICAL extends Chemical, + STACK extends ChemicalStack, + TANK extends IChemicalTank, + HANDLER extends IChemicalHandler + > + void megane_addInfo( + BlockEntity tile, + @Nullable MultiblockData structure, + Capability capability, + Function> multiBlockToTanks, + LookingAtHelper info, + ILangEntry langEntry, + MergedChemicalTank.Current matchingCurrent, + MergedTank.CurrentType matchingCurrentType) { + } + +} diff --git a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/MixinMekanismWTHITPlugin.java b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/MixinMekanismWTHITPlugin.java new file mode 100644 index 0000000..f1aa28e --- /dev/null +++ b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/mixin/MixinMekanismWTHITPlugin.java @@ -0,0 +1,25 @@ +package lol.bai.megane.module.mekanism.mixin; + +import mcp.mobius.waila.api.IRegistrar; +import mekanism.common.integration.lookingat.wthit.MekanismWTHITPlugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MekanismWTHITPlugin.class) +public class MixinMekanismWTHITPlugin { + + @Unique + private static final Logger megane_LOGGER = LoggerFactory.getLogger("MixinMekanismWTHITPlugin"); + + @Inject(method = "register", at = @At("HEAD"), remap = false, cancellable = true) + private void megane_disable(IRegistrar registration, CallbackInfo ci) { + megane_LOGGER.info("[megane-mekanism] Disabled Mekanism's builtin WTHIT compatibility in favor of Megane's"); + ci.cancel(); + } + +} diff --git a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/ChemicalProvider.java b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/ChemicalProvider.java new file mode 100644 index 0000000..2b7a582 --- /dev/null +++ b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/ChemicalProvider.java @@ -0,0 +1,148 @@ +package lol.bai.megane.module.mekanism.provider; + +import java.util.ArrayList; +import java.util.List; + +import lol.bai.megane.module.mekanism.MeganeMekaninsm; +import lol.bai.megane.module.mekanism.mixin.AccessLookingAtUtils; +import mcp.mobius.waila.api.IBlockAccessor; +import mcp.mobius.waila.api.IBlockComponentProvider; +import mcp.mobius.waila.api.IData; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.ITooltip; +import mcp.mobius.waila.api.WailaHelper; +import mcp.mobius.waila.api.component.PairComponent; +import mcp.mobius.waila.api.component.SpriteBarComponent; +import mcp.mobius.waila.api.component.WrappedComponent; +import mcp.mobius.waila.api.data.FluidData; +import mcp.mobius.waila.api.data.FluidData.Unit; +import mekanism.api.chemical.ChemicalStack; +import mekanism.api.chemical.ChemicalType; +import mekanism.api.chemical.ChemicalUtils; +import mekanism.api.chemical.merged.MergedChemicalTank; +import mekanism.api.math.FloatingLong; +import mekanism.client.render.MekanismRenderer; +import mekanism.common.MekanismLang; +import mekanism.common.capabilities.Capabilities; +import mekanism.common.capabilities.merged.MergedTank; +import mekanism.common.integration.lookingat.LookingAtHelper; +import mekanism.common.lib.multiblock.MultiblockData; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.fluids.FluidStack; +import org.jetbrains.annotations.Nullable; + +public class ChemicalProvider implements IBlockComponentProvider, IDataProvider { + + public static final ResourceLocation DATA = MeganeMekaninsm.id("chemical"); + + private static final String INFINITE = "∞"; + + @Override + public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) { + var data = accessor.getData().get(Data.class); + if (data == null || !config.getBoolean(MeganeMekaninsm.CONFIG_SHOW_CHEMICALS)) return; + + var displayUnit = config.getEnum(FluidData.CONFIG_DISPLAY_UNIT); + + for (var tank : data.tanks) { + var stack = tank.stack; + if (stack.isEmpty()) continue; + + var stored = stack.getAmount(); + var capacity = tank.capacity; + var ratio = Double.isInfinite(capacity) ? 1f : (float) stored / capacity; + + String text; + if (Double.isInfinite(stored)) text = INFINITE; + else { + text = WailaHelper.suffix((long) Unit.convert(Unit.MILLIBUCKETS, displayUnit, stored)); + if (Double.isFinite(capacity)) text += "/" + WailaHelper.suffix((long) Unit.convert(Unit.MILLIBUCKETS, displayUnit, capacity)); + } + + text += " " + displayUnit.symbol; + + var sprite = MekanismRenderer.getChemicalTexture(stack.getType()); + tooltip.addLine(new PairComponent( + new WrappedComponent(stack.getTextComponent()), + new SpriteBarComponent(ratio, sprite, 16, 16, stack.getChemicalTint(), Component.literal(text)))); + } + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + data.add(Data.class, res -> addChemicals(res, accessor.getTarget(), null)); + } + + public static void addChemicals(IDataWriter.Result res, BlockEntity tile, @Nullable MultiblockData structure) { + var info = new Data(new ArrayList<>()); + AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.GAS_HANDLER, multiblock -> multiblock.getGasTanks(null), info, MekanismLang.GAS, MergedChemicalTank.Current.GAS, MergedTank.CurrentType.GAS); + AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.INFUSION_HANDLER, multiblock -> multiblock.getInfusionTanks(null), info, MekanismLang.INFUSE_TYPE, MergedChemicalTank.Current.INFUSION, MergedTank.CurrentType.INFUSION); + AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.PIGMENT_HANDLER, multiblock -> multiblock.getPigmentTanks(null), info, MekanismLang.PIGMENT, MergedChemicalTank.Current.PIGMENT, MergedTank.CurrentType.PIGMENT); + AccessLookingAtUtils.megane_addInfo(tile, structure, Capabilities.SLURRY_HANDLER, multiblock -> multiblock.getSlurryTanks(null), info, MekanismLang.SLURRY, MergedChemicalTank.Current.SLURRY, MergedTank.CurrentType.SLURRY); + if (!info.tanks.isEmpty()) res.add(info); + } + + public static final class Blocker implements IDataProvider { + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + if (!config.getBoolean(MeganeMekaninsm.CONFIG_SHOW_CHEMICALS)) data.blockAll(Data.class); + } + + } + + public record Data(List tanks) implements IData, LookingAtHelper { + + public record Tank(ChemicalStack stack, long capacity) { + + } + + public Data(FriendlyByteBuf buf) { + this(buf.readList(b -> { + var type = b.readEnum(ChemicalType.class); + var stack = switch (type) { + case GAS -> ChemicalUtils.readGasStack(b); + case INFUSION -> ChemicalUtils.readInfusionStack(b); + case PIGMENT -> ChemicalUtils.readPigmentStack(b); + case SLURRY -> ChemicalUtils.readSlurryStack(b); + }; + var capacity = b.readVarLong(); + return new Tank(stack, capacity); + })); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeCollection(tanks, (b, t) -> { + b.writeEnum(ChemicalType.getTypeFor(t.stack)); + ChemicalUtils.writeChemicalStack(b, t.stack); + b.writeVarLong(t.capacity); + }); + } + + @Override + public void addChemicalElement(ChemicalStack stored, long capacity) { + tanks.add(new Tank(stored, capacity)); + } + + @Override + public void addText(Component text) { + } + + @Override + public void addEnergyElement(FloatingLong energy, FloatingLong maxEnergy) { + } + + @Override + public void addFluidElement(FluidStack stored, int capacity) { + } + + } + +} diff --git a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/FluidProvider.java b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/FluidProvider.java new file mode 100644 index 0000000..89ad3eb --- /dev/null +++ b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/FluidProvider.java @@ -0,0 +1,55 @@ +package lol.bai.megane.module.mekanism.provider; + +import lol.bai.megane.module.mekanism.mixin.AccessLookingAtUtils; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.data.FluidData; +import mcp.mobius.waila.api.forge.ForgeFluidData; +import mekanism.api.chemical.ChemicalStack; +import mekanism.api.math.FloatingLong; +import mekanism.common.integration.lookingat.LookingAtHelper; +import mekanism.common.util.CapabilityUtils; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.IFluidHandler; + +public class FluidProvider implements IDataProvider, LookingAtHelper { + + private FluidData.PlatformDependant fluidData; + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + data.add(FluidData.class, res -> CapabilityUtils + .getCapability(accessor.getTarget(), ForgeCapabilities.FLUID_HANDLER, null) + .ifPresent(handler -> addFluids(res, handler))); + } + + public void addFluids(IDataWriter.Result res, IFluidHandler handler) { + fluidData = ForgeFluidData.of(); + AccessLookingAtUtils.megane_displayFluid(this, handler); + res.add(fluidData); + fluidData = null; + } + + @Override + public void addFluidElement(FluidStack stored, int capacity) { + fluidData.add(stored, capacity); + } + + @Override + public void addText(Component text) { + } + + @Override + public void addEnergyElement(FloatingLong energy, FloatingLong maxEnergy) { + } + + @Override + public void addChemicalElement(ChemicalStack stored, long capacity) { + } + +} diff --git a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/MultiblockProvider.java b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/MultiblockProvider.java new file mode 100644 index 0000000..227d874 --- /dev/null +++ b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/MultiblockProvider.java @@ -0,0 +1,39 @@ +package lol.bai.megane.module.mekanism.provider; + +import lol.bai.megane.module.mekanism.mixin.AccessLookingAtUtils; +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.data.EnergyData; +import mcp.mobius.waila.api.data.FluidData; +import mcp.mobius.waila.api.data.ItemData; +import net.minecraft.world.level.block.entity.BlockEntity; + +public class MultiblockProvider implements IDataProvider { + + private final FluidProvider fluidProvider; + + public MultiblockProvider(FluidProvider fluidProvider) { + this.fluidProvider = fluidProvider; + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + var multiblock = AccessLookingAtUtils.megane_getMultiblock(accessor.getTarget()); + if (multiblock == null || !multiblock.isFormed()) return; + + data.add(EnergyData.class, res -> + StrictEnergyProvider.addEnergy(res, multiblock)); + + data.add(FluidData.class, res -> + fluidProvider.addFluids(res, multiblock)); + + data.add(ItemData.class, res -> + res.add(ItemData.of(config).getter(multiblock::getStackInSlot, multiblock.getSlots()))); + + data.add(ChemicalProvider.Data.class, res -> + ChemicalProvider.addChemicals(res, accessor.getTarget(), multiblock)); + } + +} diff --git a/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/StrictEnergyProvider.java b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/StrictEnergyProvider.java new file mode 100644 index 0000000..18bfb94 --- /dev/null +++ b/modules/forge/mekanism/src/main/java/lol/bai/megane/module/mekanism/provider/StrictEnergyProvider.java @@ -0,0 +1,33 @@ +package lol.bai.megane.module.mekanism.provider; + +import mcp.mobius.waila.api.IDataProvider; +import mcp.mobius.waila.api.IDataWriter; +import mcp.mobius.waila.api.IPluginConfig; +import mcp.mobius.waila.api.IServerAccessor; +import mcp.mobius.waila.api.data.EnergyData; +import mekanism.api.energy.IStrictEnergyHandler; +import mekanism.common.capabilities.Capabilities; +import net.minecraft.world.level.block.entity.BlockEntity; + +public class StrictEnergyProvider implements IDataProvider { + + public static void addEnergy(IDataWriter.Result res, IStrictEnergyHandler handler) { + var count = handler.getEnergyContainerCount(); + var stored = 0.0; + var max = 0.0; + for (int i = 0; i < count; i++) { + stored += handler.getEnergy(i).doubleValue(); + max += handler.getMaxEnergy(i).doubleValue(); + } + + res.add(EnergyData.of(stored, max)); + } + + @Override + public void appendData(IDataWriter data, IServerAccessor accessor, IPluginConfig config) { + data.add(EnergyData.class, res -> accessor.getTarget() + .getCapability(Capabilities.STRICT_ENERGY) + .ifPresent(handler -> addEnergy(res, handler))); + } + +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 1c73166..e6bb6d9 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -46,7 +46,7 @@ forge("applied-energistics-2") forge("create") forge("immersive-engineering") forge("lapis-reserve") -//forge("mekanism") +forge("mekanism") forge("productive-bees") //forge("refined-storage") forge("resource-chickens")