Skip to content

Commit

Permalink
Display the maximum input and output rates, and average I/O in ATs. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorbatron authored Oct 4, 2024
1 parent 3bc2560 commit d3dc81c
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import gregtech.api.pattern.FactoryBlockPattern;
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.util.TextComponentUtil;
import gregtech.api.util.TextFormattingUtil;
import gregtech.client.renderer.ICubeRenderer;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.utils.TooltipHelper;
Expand All @@ -30,6 +32,7 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.relauncher.Side;
Expand All @@ -50,6 +53,8 @@ public class MetaTileEntityActiveTransformer extends MultiblockWithDisplayBase i
private IEnergyContainer powerOutput;
private IEnergyContainer powerInput;
private boolean isActive = false;
private long averageIOLastSec;
private long netIOLastSec;

public MetaTileEntityActiveTransformer(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
Expand All @@ -64,10 +69,18 @@ public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) {

@Override
protected void updateFormedValid() {
if (isWorkingEnabled()) {
long canDrain = powerInput.getEnergyStored();
long totalDrained = powerOutput.changeEnergy(canDrain);
powerInput.removeEnergy(totalDrained);
if (!getWorld().isRemote) {
if ((getOffsetTimer() % 20) == 0) {
averageIOLastSec = netIOLastSec / 20;
netIOLastSec = 0;
}

if (isWorkingEnabled()) {
long canDrain = powerInput.getEnergyStored();
long totalDrained = powerOutput.changeEnergy(canDrain);
powerInput.removeEnergy(totalDrained);
netIOLastSec += totalDrained;
}
}
}

Expand Down Expand Up @@ -159,7 +172,39 @@ protected void addDisplayText(List<ITextComponent> textList) {
"gregtech.multiblock.idling",
"gregtech.multiblock.idling",
"gregtech.machine.active_transformer.routing")
.addWorkingStatusLine();
.addWorkingStatusLine()
.addCustom(tl -> {
if (isStructureFormed()) {
// Max input line
ITextComponent maxInputFormatted = TextComponentUtil.stringWithColor(
TextFormatting.WHITE,
TextFormattingUtil.formatNumbers(
powerInput.getInputVoltage() * powerInput.getInputAmperage()) + " EU/t");
tl.add(TextComponentUtil.translationWithColor(
TextFormatting.GREEN,
"gregtech.multiblock.active_transformer.max_in",
maxInputFormatted));

// Max output line
ITextComponent maxOutputFormatted = TextComponentUtil.stringWithColor(
TextFormatting.WHITE,
TextFormattingUtil.formatNumbers(
powerOutput.getOutputVoltage() * powerOutput.getOutputAmperage()) + " EU/t");
tl.add(TextComponentUtil.translationWithColor(
TextFormatting.RED,
"gregtech.multiblock.active_transformer.max_out",
maxOutputFormatted));

// Average I/O line
ITextComponent avgInputFormatted = TextComponentUtil.stringWithColor(
TextFormatting.WHITE,
TextFormattingUtil.formatNumbers(averageIOLastSec) + " EU/t");
tl.add(TextComponentUtil.translationWithColor(
TextFormatting.AQUA,
"gregtech.multiblock.active_transformer.average_io",
avgInputFormatted));
}
});
}

@Override
Expand Down Expand Up @@ -255,4 +300,8 @@ public void addInformation(ItemStack stack, @Nullable World world, @NotNull List
tooltip.add(I18n.format("gregtech.machine.active_transformer.tooltip3") + TooltipHelper.RAINBOW_SLOW +
I18n.format("gregtech.machine.active_transformer.tooltip3.5"));
}

public long getAverageIOLastSec() {
return this.averageIOLastSec;
}
}
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 @@ -40,6 +40,7 @@ public void register(IWailaRegistrar registrar) {
// one day, if cover provider is ported to waila, register it right here
BlockOreDataProvider.INSTANCE.register(registrar);
LampDataProvider.INSTANCE.register(registrar);
ActiveTransformerDataProvider.INSTANCE.register(registrar);
}

/** Render an ItemStack. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package gregtech.integration.hwyla.provider;

import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IMultiblockController;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.multi.electric.MetaTileEntityActiveTransformer;

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 ActiveTransformerDataProvider extends CapabilityDataProvider<IMultiblockController> {

public static final ActiveTransformerDataProvider INSTANCE = new ActiveTransformerDataProvider();

@Override
public void register(@NotNull IWailaRegistrar registrar) {
registrar.registerBodyProvider(this, TileEntity.class);
registrar.registerNBTProvider(this, TileEntity.class);
registrar.addConfig(GTValues.MOD_NAME, "gregtech.multiblock.activetransformer");
}

@Override
protected @NotNull Capability<IMultiblockController> getCapability() {
return GregtechCapabilities.CAPABILITY_MULTIBLOCK_CONTROLLER;
}

@Override
protected NBTTagCompound getNBTData(IMultiblockController capability, NBTTagCompound tag) {
if (capability instanceof MetaTileEntityActiveTransformer activeTransformer) {
if (activeTransformer.isStructureFormed() && activeTransformer.isActive()) {
NBTTagCompound subTag = new NBTTagCompound();

subTag.setLong("AverageIO", activeTransformer.getAverageIOLastSec());

tag.setTag("gregtech.IMultiblockController.ActiveTransformer", subTag);
}
}
return tag;
}

@Override
@NotNull
public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
if (!config.getConfig("gregtech.multiblock") || accessor.getTileEntity() == null) {
return tooltip;
}

if (accessor.getNBTData().hasKey("gregtech.IMultiblockController.ActiveTransformer")) {
NBTTagCompound tag = accessor.getNBTData()
.getCompoundTag("gregtech.IMultiblockController.ActiveTransformer");

tooltip.add(I18n.format("gregtech.waila.active_transformer.average_io",
TextFormattingUtil.formatNumbers(tag.getLong("AverageIO"))));
}

return tooltip;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void init(FMLInitializationEvent event) {
oneProbe.registerProvider(new LampInfoProvider());
oneProbe.registerProvider(new LDPipeProvider());
oneProbe.registerProvider(new LaserContainerInfoProvider());
oneProbe.registerProvider(new ActiveTransformerInfoProvider());

// Dev environment debug providers
oneProbe.registerProvider(new DebugPipeNetInfoProvider());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package gregtech.integration.theoneprobe.provider;

import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IMultiblockController;
import gregtech.api.util.TextComponentUtil;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.multi.electric.MetaTileEntityActiveTransformer;

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 ActiveTransformerInfoProvider extends CapabilityInfoProvider<IMultiblockController> {

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

@Override
protected boolean allowDisplaying(@NotNull IMultiblockController capability) {
return capability instanceof MetaTileEntityActiveTransformer activeTransformer && activeTransformer.isActive();
}

@Override
protected @NotNull Capability<IMultiblockController> getCapability() {
return GregtechCapabilities.CAPABILITY_MULTIBLOCK_CONTROLLER;
}

@Override
protected void addProbeInfo(IMultiblockController capability, IProbeInfo probeInfo, EntityPlayer player,
TileEntity tileEntity, IProbeHitData data) {
long averageIO = ((MetaTileEntityActiveTransformer) capability).getAverageIOLastSec();
ITextComponent text = TextComponentUtil.translationWithColor(
TextFormatting.AQUA,
"gregtech.multiblock.active_transformer.average_io",
TextComponentUtil.stringWithColor(TextFormatting.WHITE,
player.isSneaking() || averageIO < 10_000 ?
TextFormattingUtil.formatNumbers(averageIO) + " EU/t" :
ElementProgress.format(averageIO, NumberFormat.COMPACT, "EU/t")));

probeInfo.text(text.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 @@ -124,6 +124,7 @@ gregtech.waila.progress_idle=Idle
gregtech.waila.progress_tick=Progress: %d t / %d t
gregtech.waila.progress_sec=Progress: %d s / %d s
gregtech.waila.progress_computation=Computation: %s / %s
gregtech.waila.active_transformer.average_io=Average I/O: %s EU/t

gregtech.multiblock.title=Multiblock Pattern
gregtech.multiblock.primitive_blast_furnace.bronze.description=The Primitive Blast Furnace (PBF) is a multiblock structure used for cooking steel in the early game. Although not very fast, it will provide you with steel for your first setups.
Expand Down Expand Up @@ -4890,6 +4891,9 @@ gregtech.machine.active_transformer.tooltip3=Can transmit power at incredible di
gregtech.machine.active_transformer.tooltip3.5= Lasers§7.
gregtech.multiblock.active_transformer.description=The Active Transformer is a multiblock structure that can accept any number or tier of Energy Hatches, and transform them into any number or tier of Dynamo Hatches. They can be chained with Laser Source and Target Hatches, allowing long distance power transportation without any losses. Lasers must be in a straight line, otherwise they will not send energy.
gregtech.machine.active_transformer.routing=Routing.
gregtech.multiblock.active_transformer.max_in=Max Input: %s
gregtech.multiblock.active_transformer.max_out=Max Output: %s
gregtech.multiblock.active_transformer.average_io=Average I/O: %s

gregtech.machine.research_station.name=Research Station
gregtech.machine.research_station.tooltip.1=More than just a Multiblock Scanner
Expand Down

0 comments on commit d3dc81c

Please sign in to comment.