Skip to content
9 changes: 9 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@
"config.gtceu.option.yOffset": "ʇǝsɟɟOʎ",
"config.gtceu.option.zombieSpawnWithSabers": "sɹǝqɐSɥʇıMuʍɐdSǝıqɯoz",
"config.jade.plugin_gtceu.auto_output_info": "oɟuI ʇndʇnO oʇnⱯ ]nƎƆ⟘⅁[",
"config.jade.plugin_gtceu.battery_info": "oɟuı ʎɹǝʇʇɐᗺ ]nƎƆ⟘⅁[",
"config.jade.plugin_gtceu.cable_info": "oɟuI ǝןqɐƆ ]nƎƆ⟘⅁[",
"config.jade.plugin_gtceu.controllable_provider": "ǝןqɐןןoɹʇuoƆ ]nƎƆ⟘⅁[",
"config.jade.plugin_gtceu.data_bank": "oɟuI ʞuɐᗺ ɐʇɐᗡ ]nƎƆ⟘⅁[",
Expand Down Expand Up @@ -2491,12 +2492,20 @@
"gtceu.item_pipe.priority": "%dɟ§ :ʎʇıɹoıɹԀ6§",
"gtceu.jade.amperage_use": "Ɐ %s",
"gtceu.jade.at": " @ ",
"gtceu.jade.changes_eu_sec": "s/∩Ǝ %s",
"gtceu.jade.cleaned_this_second": "s/%s :pɹɐzɐɥ pǝuɐǝןƆ",
"gtceu.jade.days": "sʎɐp %s",
"gtceu.jade.energy_stored": "∩Ǝ %d / %d",
"gtceu.jade.fluid_use": "ʇ/ᗺɯ %s",
"gtceu.jade.hours": "sɹnoɥ %s",
"gtceu.jade.minutes": "sǝʇnuıɯ %s",
"gtceu.jade.progress_computation": "∩MƆ %s / %s",
"gtceu.jade.progress_sec": "s %s / %s",
"gtceu.jade.progress_tick": "ʇ %s / %s",
"gtceu.jade.remaining_charge_time": "%s :pǝbɹɐɥɔ ןıʇu∩",
"gtceu.jade.remaining_discharge_time": "%s :ʎʇdɯǝ ןıʇu∩",
"gtceu.jade.seconds": "spuoɔǝs %s",
"gtceu.jade.years": "sɹɐǝʎ %s",
"gtceu.jei.bedrock_fluid.heavy_oil_deposit": "ʇısodǝᗡ ןıO ʎʌɐǝH",
"gtceu.jei.bedrock_fluid.lava_deposit": "ʇısodǝᗡ ɐʌɐꞀ",
"gtceu.jei.bedrock_fluid.light_oil_deposit": "ʇısodǝᗡ ןıO ʇɥbıꞀ",
Expand Down
9 changes: 9 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@
"config.gtceu.option.yOffset": "yOffset",
"config.gtceu.option.zombieSpawnWithSabers": "zombieSpawnWithSabers",
"config.jade.plugin_gtceu.auto_output_info": "[GTCEu] Auto Output Info",
"config.jade.plugin_gtceu.battery_info": "[GTCEu] Battery info",
"config.jade.plugin_gtceu.cable_info": "[GTCEu] Cable Info",
"config.jade.plugin_gtceu.controllable_provider": "[GTCEu] Controllable",
"config.jade.plugin_gtceu.data_bank": "[GTCEu] Data Bank Info",
Expand Down Expand Up @@ -2491,12 +2492,20 @@
"gtceu.item_pipe.priority": "§9Priority: §f%d",
"gtceu.jade.amperage_use": "%s A",
"gtceu.jade.at": " @ ",
"gtceu.jade.changes_eu_sec": "%s EU/s",
"gtceu.jade.cleaned_this_second": "Cleaned hazard: %s/s",
"gtceu.jade.days": "%s days",
"gtceu.jade.energy_stored": "%d / %d EU",
"gtceu.jade.fluid_use": "%s mB/t",
"gtceu.jade.hours": "%s hours",
"gtceu.jade.minutes": "%s minutes",
"gtceu.jade.progress_computation": "%s / %s CWU",
"gtceu.jade.progress_sec": "%s / %s s",
"gtceu.jade.progress_tick": "%s / %s t",
"gtceu.jade.remaining_charge_time": "Until charged: %s",
"gtceu.jade.remaining_discharge_time": "Until empty: %s",
"gtceu.jade.seconds": "%s seconds",
"gtceu.jade.years": "%s years",
"gtceu.jei.bedrock_fluid.heavy_oil_deposit": "Heavy Oil Deposit",
"gtceu.jei.bedrock_fluid.lava_deposit": "Lava Deposit",
"gtceu.jei.bedrock_fluid.light_oil_deposit": "Light Oil Deposit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ private static void initWailaLikeLang(RegistrateLangProvider provider) {
provider.add("gtceu.jade.fluid_use", "%s mB/t");
provider.add("gtceu.jade.amperage_use", "%s A");
provider.add("gtceu.jade.at", " @ ");
provider.add("gtceu.jade.remaining_charge_time", "Until charged: %s");
provider.add("gtceu.jade.remaining_discharge_time", "Until empty: %s");
provider.add("gtceu.jade.changes_eu_sec", "%s EU/s");
provider.add("gtceu.jade.seconds", "%s seconds");
provider.add("gtceu.jade.minutes", "%s minutes");
provider.add("gtceu.jade.hours", "%s hours");
provider.add("gtceu.jade.days", "%s days");
provider.add("gtceu.jade.years", "%s years");

provider.add("gtceu.top.energy_stored", " / %d EU");
provider.add("gtceu.top.progress_computation", " / %s CWU");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ public static void init(RegistrateLangProvider provider) {
"GregTech has modified the debug info! For Developers: enable the misc:debug config option in the GregTech config file to see more");
provider.add("config.jade.plugin_gtceu.controllable_provider", "[GTCEu] Controllable");
provider.add("config.jade.plugin_gtceu.workable_provider", "[GTCEu] Workable");
provider.add("config.jade.plugin_gtceu.battery_info", "[GTCEu] Battery info");
provider.add("config.jade.plugin_gtceu.electric_container_provider", "[GTCEu] Electric Container");
provider.add("config.jade.plugin_gtceu.recipe_logic_provider", "[GTCEu] Recipe Logic");
provider.add("config.jade.plugin_gtceu.hazard_cleaner_provider", "[GTCEu] Hazard Cleaner");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void register(IWailaCommonRegistration registration) {
registration.registerBlockDataProvider(new PrimitivePumpBlockProvider(), BlockEntity.class);
registration.registerBlockDataProvider(new DataBankBlockProvider(), BlockEntity.class);
registration.registerBlockDataProvider(new EnergyConverterModeProvider(), BlockEntity.class);
registration.registerBlockDataProvider(new BatteryStorageInfoProvider(), BlockEntity.class);
registration.registerBlockDataProvider(new LDPEndpointProvider(), BlockEntity.class);
if (GTCEu.Mods.isAE2Loaded()) {
registration.registerBlockDataProvider(new MEPatternBufferProvider(), BlockEntity.class);
Expand Down Expand Up @@ -77,6 +78,7 @@ public void registerClient(IWailaClientRegistration registration) {
registration.registerBlockComponent(new DataBankBlockProvider(), Block.class);
registration.registerBlockComponent(new LDPEndpointProvider(), Block.class);
registration.registerBlockComponent(new EnergyConverterModeProvider(), Block.class);
registration.registerBlockComponent(new BatteryStorageInfoProvider(), Block.class);
if (GTCEu.Mods.isAE2Loaded()) {
registration.registerBlockComponent(new MEPatternBufferProvider(), Block.class);
registration.registerBlockComponent(new MEPatternBufferProxyProvider(), Block.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.gregtechceu.gtceu.integration.jade.provider;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.GTValues;
import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper;
import com.gregtechceu.gtceu.api.capability.IElectricItem;
import com.gregtechceu.gtceu.api.capability.IEnergyContainer;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.transfer.item.CustomItemStackHandler;
import com.gregtechceu.gtceu.common.machine.electric.BatteryBufferMachine;
import com.gregtechceu.gtceu.common.machine.electric.ChargerMachine;

import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;

import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.IServerDataProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;
import snownee.jade.api.ui.IElementHelper;

import static com.gregtechceu.gtceu.utils.GTUtil.formatLongNumber;
import static com.gregtechceu.gtceu.utils.GTUtil.getStringRemainTime;

public class BatteryStorageInfoProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> {

@Override
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
if (blockEntity.getMetaMachine() instanceof ChargerMachine ||
blockEntity.getMetaMachine() instanceof BatteryBufferMachine) {
CompoundTag serverData = blockAccessor.getServerData();
if (serverData.contains("batteries")) {
CompoundTag tag = serverData.getCompound("batteries");
CompoundTag container = tag.getCompound("energy");
long changed = container.getLong("changed"), stored = container.getLong("stored"),
capacity = container.getLong("capacity");
iTooltip.add(Component.translatable("gtceu.jade.changes_eu_sec", formatLongNumber(changed)));
if (changed > 0L) {
iTooltip.add(Component
.translatable("gtceu.jade.remaining_charge_time",
getStringRemainTime((capacity - stored) / changed)));
} else if (changed < 0L) {
iTooltip.add(Component.translatable("gtceu.jade.remaining_discharge_time",
getStringRemainTime((stored) / -changed)));
}
if (Minecraft.getInstance().player.isShiftKeyDown()) {
CustomItemStackHandler handler = new CustomItemStackHandler();
handler.deserializeNBT(tag.getCompound("storage"));
IElementHelper helper = iTooltip.getElementHelper();
for (int i = 0; i < handler.getSlots(); i++) {
if (handler.getStackInSlot(i).getCount() != 0) {
ItemStack stack = handler.getStackInSlot(i);
iTooltip.add(helper.smallItem(stack));
IElectricItem item = GTCapabilityHelper.getElectricItem(stack);
if (item == null) continue;
iTooltip.append(Component.literal(
GTValues.VNF[item.getTier()] + "§r " + formatLongNumber(item.getCharge()) +
" / " + formatLongNumber(item.getMaxCharge()) + " EU"));
}
}
}
}
}
}
}

private CompoundTag getEnergyData(IEnergyContainer container) {
CompoundTag tag = new CompoundTag();
tag.putLong("changed", container.getInputPerSec() - container.getOutputPerSec());
tag.putLong("capacity", container.getEnergyCapacity());
tag.putLong("stored", container.getEnergyStored());
return tag;
}

@Override
public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccessor) {
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
if (blockEntity.getMetaMachine() instanceof ChargerMachine machine) {
CompoundTag tag = new CompoundTag();
tag.put("energy", getEnergyData(machine.energyContainer));
tag.put("storage", machine.getChargerInventory().serializeNBT());
compoundTag.put("batteries", tag);
} else if (blockEntity.getMetaMachine() instanceof BatteryBufferMachine machine) {
CompoundTag tag = new CompoundTag();
IEnergyContainer container = machine.energyContainer;
tag.put("energy", getEnergyData(machine.energyContainer));
tag.put("storage", machine.getBatteryInventory().serializeNBT());
compoundTag.put("batteries", tag);
}
}
}

@Override
public ResourceLocation getUid() {
return GTCEu.id("battery_info");
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.util.function.Function;

import static com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey.HAZARD;
import static com.gregtechceu.gtceu.utils.FormattingUtil.DECIMAL_FORMAT_SIC_2F;

public class GTUtil {

Expand Down Expand Up @@ -360,6 +361,40 @@ public static boolean isAltDown() {
return false;
}

public static String formatLongNumber(long number, long threshold) {
return (number > threshold) ? DECIMAL_FORMAT_SIC_2F.format(number) : String.valueOf(number);
}

public static String formatLongNumber(long number) {
return formatLongNumber(number, 10000);
}

public static String getStringRemainTime(long time, long threshold) {
String s = Component.translatable("gtceu.jade.seconds", time % 60).getString();
time /= 60;
if (time > 0) {
s = Component.translatable("gtceu.jade.minutes", time % 60).getString() + " " + s;
time /= 60;
if (time > 0) {
s = Component.translatable("gtceu.jade.hours", time % 60).getString() + " " + s;
time /= 60;
if (time > 0) {
s = Component.translatable("gtceu.jade.days", time % 24).getString() + " " + s;
time /= 24;
if (time > 0) {
s = Component.translatable("gtceu.jade.years", formatLongNumber(time, threshold)).getString() +
" " + s;
}
}
}
}
return s;
}

public static String getStringRemainTime(long time) {
return getStringRemainTime(time, 10000);
}

public static boolean isFluidStackAmountDivisible(FluidStack fluidStack, int divisor) {
return fluidStack.getAmount() % divisor == 0 && fluidStack.getAmount() % divisor != fluidStack.getAmount() &&
fluidStack.getAmount() / divisor != 0;
Expand Down