Skip to content

Commit

Permalink
Add the power I/O of battery buffers to TOP/WAILA/HWYLA (#2596)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorbatron authored Oct 4, 2024
1 parent d3dc81c commit fefa378
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtech/integration/hwyla/HWYLAModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IEnergyContainer> {

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<IEnergyContainer> 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<String> getWailaBody(ItemStack itemStack, List<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IEnergyContainer> {

@Override
public String getID() {
return GTValues.MODID + ":battery_buffer_provider";
}

@Override
protected @NotNull Capability<IEnergyContainer> 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());
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fefa378

Please sign in to comment.