From fefa378302cb69ae72484ab3eb112a7a8d10b54a Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:30:26 -0400 Subject: [PATCH] Add the power I/O of battery buffers to TOP/WAILA/HWYLA (#2596) --- .../integration/hwyla/HWYLAModule.java | 1 + .../provider/BatteryBufferDataProvider.java | 79 +++++++++++++++++++ .../theoneprobe/TheOneProbeModule.java | 1 + .../provider/BatteryBufferInfoProvider.java | 67 ++++++++++++++++ .../resources/assets/gregtech/lang/en_us.lang | 4 + 5 files changed, 152 insertions(+) create mode 100644 src/main/java/gregtech/integration/hwyla/provider/BatteryBufferDataProvider.java create mode 100644 src/main/java/gregtech/integration/theoneprobe/provider/BatteryBufferInfoProvider.java diff --git a/src/main/java/gregtech/integration/hwyla/HWYLAModule.java b/src/main/java/gregtech/integration/hwyla/HWYLAModule.java index 6b0a71618fa..a604d6331e1 100644 --- a/src/main/java/gregtech/integration/hwyla/HWYLAModule.java +++ b/src/main/java/gregtech/integration/hwyla/HWYLAModule.java @@ -41,6 +41,7 @@ public void register(IWailaRegistrar registrar) { BlockOreDataProvider.INSTANCE.register(registrar); LampDataProvider.INSTANCE.register(registrar); ActiveTransformerDataProvider.INSTANCE.register(registrar); + BatteryBufferDataProvider.INSTANCE.register(registrar); } /** Render an ItemStack. */ diff --git a/src/main/java/gregtech/integration/hwyla/provider/BatteryBufferDataProvider.java b/src/main/java/gregtech/integration/hwyla/provider/BatteryBufferDataProvider.java new file mode 100644 index 00000000000..67f08fd7737 --- /dev/null +++ b/src/main/java/gregtech/integration/hwyla/provider/BatteryBufferDataProvider.java @@ -0,0 +1,79 @@ +package gregtech.integration.hwyla.provider; + +import gregtech.api.GTValues; +import gregtech.api.capability.GregtechCapabilities; +import gregtech.api.capability.IEnergyContainer; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.util.TextFormattingUtil; +import gregtech.common.metatileentities.electric.MetaTileEntityBatteryBuffer; + +import net.minecraft.client.resources.I18n; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.capabilities.Capability; + +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import mcp.mobius.waila.api.IWailaRegistrar; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class BatteryBufferDataProvider extends CapabilityDataProvider { + + public static final BatteryBufferDataProvider INSTANCE = new BatteryBufferDataProvider(); + + @Override + public void register(@NotNull IWailaRegistrar registrar) { + registrar.registerBodyProvider(this, TileEntity.class); + registrar.registerNBTProvider(this, TileEntity.class); + registrar.addConfig(GTValues.MOD_NAME, "gregtech.battery-buffer"); + } + + @Override + protected @NotNull Capability getCapability() { + return GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER; + } + + @Override + protected NBTTagCompound getNBTData(IEnergyContainer capability, NBTTagCompound tag) { + NBTTagCompound subTag = new NBTTagCompound(); + subTag.setLong("InputPerSec", capability.getInputPerSec()); + subTag.setLong("OutputPerSec", capability.getOutputPerSec()); + tag.setTag("gregtech.BatteryBuffer", subTag); + return tag; + } + + @Override + @NotNull + public List getWailaBody(ItemStack itemStack, List tooltip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + if (!config.getConfig("gregtech.battery-buffer") || accessor.getTileEntity() == null) { + return tooltip; + } + + if (accessor.getNBTData().hasKey("gregtech.BatteryBuffer")) { + NBTTagCompound batteryTag = accessor.getNBTData().getCompoundTag("gregtech.BatteryBuffer"); + + if (accessor.getTileEntity() instanceof IGregTechTileEntity iGregTechTileEntity) { + MetaTileEntity metaTileEntity = iGregTechTileEntity.getMetaTileEntity(); + + if (metaTileEntity instanceof MetaTileEntityBatteryBuffer) { + long averageIn = batteryTag.getLong("InputPerSec") / 20; + String averageInFormatted = I18n.format("gregtech.waila.energy_input", + TextFormattingUtil.formatNumbers(averageIn)); + tooltip.add(averageInFormatted); + + long averageOut = batteryTag.getLong("OutputPerSec") / 20; + String averageOutFormatted = I18n.format("gregtech.waila.energy_output", + TextFormattingUtil.formatNumbers(averageOut)); + tooltip.add(averageOutFormatted); + } + } + } + + return tooltip; + } +} diff --git a/src/main/java/gregtech/integration/theoneprobe/TheOneProbeModule.java b/src/main/java/gregtech/integration/theoneprobe/TheOneProbeModule.java index 879e7221002..6be618fabb6 100644 --- a/src/main/java/gregtech/integration/theoneprobe/TheOneProbeModule.java +++ b/src/main/java/gregtech/integration/theoneprobe/TheOneProbeModule.java @@ -44,6 +44,7 @@ public void init(FMLInitializationEvent event) { oneProbe.registerProvider(new LDPipeProvider()); oneProbe.registerProvider(new LaserContainerInfoProvider()); oneProbe.registerProvider(new ActiveTransformerInfoProvider()); + oneProbe.registerProvider(new BatteryBufferInfoProvider()); // Dev environment debug providers oneProbe.registerProvider(new DebugPipeNetInfoProvider()); diff --git a/src/main/java/gregtech/integration/theoneprobe/provider/BatteryBufferInfoProvider.java b/src/main/java/gregtech/integration/theoneprobe/provider/BatteryBufferInfoProvider.java new file mode 100644 index 00000000000..0c990604954 --- /dev/null +++ b/src/main/java/gregtech/integration/theoneprobe/provider/BatteryBufferInfoProvider.java @@ -0,0 +1,67 @@ +package gregtech.integration.theoneprobe.provider; + +import gregtech.api.GTValues; +import gregtech.api.capability.GregtechCapabilities; +import gregtech.api.capability.IEnergyContainer; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; +import gregtech.api.util.TextComponentUtil; +import gregtech.api.util.TextFormattingUtil; +import gregtech.common.metatileentities.electric.MetaTileEntityBatteryBuffer; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.common.capabilities.Capability; + +import mcjty.theoneprobe.api.IProbeHitData; +import mcjty.theoneprobe.api.IProbeInfo; +import mcjty.theoneprobe.api.NumberFormat; +import mcjty.theoneprobe.apiimpl.elements.ElementProgress; +import org.jetbrains.annotations.NotNull; + +public class BatteryBufferInfoProvider extends CapabilityInfoProvider { + + @Override + public String getID() { + return GTValues.MODID + ":battery_buffer_provider"; + } + + @Override + protected @NotNull Capability getCapability() { + return GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER; + } + + @Override + protected void addProbeInfo(IEnergyContainer capability, IProbeInfo probeInfo, EntityPlayer player, + TileEntity tileEntity, IProbeHitData data) { + if (tileEntity instanceof IGregTechTileEntity iGregTechTileEntity) { + MetaTileEntity metaTileEntity = iGregTechTileEntity.getMetaTileEntity(); + + if (metaTileEntity instanceof MetaTileEntityBatteryBuffer) { + long averageIn = capability.getInputPerSec() / 20; + ITextComponent averageInFormatted = TextComponentUtil.translationWithColor( + TextFormatting.GREEN, + "gregtech.battery_buffer.average_input.top", + TextComponentUtil.stringWithColor( + TextFormatting.WHITE, + player.isSneaking() || averageIn < 10_000 ? + TextFormattingUtil.formatNumbers(averageIn) + " EU/t" : + ElementProgress.format(averageIn, NumberFormat.COMPACT, "EU/t"))); + probeInfo.text(averageInFormatted.getFormattedText()); + + long averageOut = capability.getOutputPerSec() / 20; + ITextComponent averageOutFormatted = TextComponentUtil.translationWithColor( + TextFormatting.RED, + "gregtech.battery_buffer.average_output.top", + TextComponentUtil.stringWithColor( + TextFormatting.WHITE, + player.isSneaking() || averageOut < 10_000 ? + TextFormattingUtil.formatNumbers(averageOut) + " EU/t" : + ElementProgress.format(averageOut, NumberFormat.COMPACT, "EU/t"))); + probeInfo.text(averageOutFormatted.getFormattedText()); + } + } + } +} diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 04bc3d45717..098b51612ee 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -120,6 +120,8 @@ option.gregtech.transformer=Transformers option.gregtech.workable=Workable Machines gregtech.waila.energy_stored=Energy: %s EU / %s EU +gregtech.waila.energy_input=Input: %s EU/t +gregtech.waila.energy_output=Output: %s EU/t gregtech.waila.progress_idle=Idle gregtech.waila.progress_tick=Progress: %d t / %d t gregtech.waila.progress_sec=Progress: %d s / %d s @@ -4161,6 +4163,8 @@ gregtech.machine.battery_buffer.max.16.name=Maximum Voltage 16x Battery Buffer gregtech.battery_buffer.average_input=Average input: %s EU/t gregtech.battery_buffer.average_output=Average output: %s EU/t +gregtech.battery_buffer.average_input.top=Input: %s +gregtech.battery_buffer.average_output.top=Output: %s # Transformers gregtech.machine.transformer.description=Transforms Energy between voltage tiers