-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the power I/O of battery buffers to TOP/WAILA/HWYLA (#2596)
- Loading branch information
Showing
5 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
src/main/java/gregtech/integration/hwyla/provider/BatteryBufferDataProvider.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,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; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/main/java/gregtech/integration/theoneprobe/provider/BatteryBufferInfoProvider.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,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()); | ||
} | ||
} | ||
} | ||
} |
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