|
| 1 | +package com.gregtechceu.gtceu.integration.jade.provider; |
| 2 | + |
| 3 | +import com.gregtechceu.gtceu.GTCEu; |
| 4 | +import com.gregtechceu.gtceu.api.GTValues; |
| 5 | +import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; |
| 6 | +import com.gregtechceu.gtceu.api.machine.MetaMachine; |
| 7 | +import com.gregtechceu.gtceu.common.machine.multiblock.electric.research.DataBankMachine; |
| 8 | +import com.gregtechceu.gtceu.utils.FormattingUtil; |
| 9 | +import com.gregtechceu.gtceu.utils.GTUtil; |
| 10 | + |
| 11 | +import net.minecraft.nbt.CompoundTag; |
| 12 | +import net.minecraft.network.chat.Component; |
| 13 | +import net.minecraft.resources.ResourceLocation; |
| 14 | + |
| 15 | +import snownee.jade.api.BlockAccessor; |
| 16 | +import snownee.jade.api.IBlockComponentProvider; |
| 17 | +import snownee.jade.api.IServerDataProvider; |
| 18 | +import snownee.jade.api.ITooltip; |
| 19 | +import snownee.jade.api.config.IPluginConfig; |
| 20 | + |
| 21 | +public class DataBankBlockProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> { |
| 22 | + |
| 23 | + @Override |
| 24 | + public ResourceLocation getUid() { |
| 25 | + return GTCEu.id("data_bank"); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) { |
| 30 | + if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) { |
| 31 | + MetaMachine machine = blockEntity.getMetaMachine(); |
| 32 | + if (machine instanceof DataBankMachine) { |
| 33 | + long energyUsage = blockAccessor.getServerData().getLong("energyUsage"); |
| 34 | + String energyFormatted = FormattingUtil.formatNumbers(energyUsage); |
| 35 | + // wrap in text component to keep it from being formatted |
| 36 | + Component voltageName = Component.literal(GTValues.VNF[GTUtil.getTierByVoltage(energyUsage)]); |
| 37 | + Component text = Component.translatable( |
| 38 | + "gtceu.multiblock.energy_consumption", |
| 39 | + energyFormatted, |
| 40 | + voltageName); |
| 41 | + |
| 42 | + iTooltip.add(text); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccessor) { |
| 49 | + if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) { |
| 50 | + MetaMachine machine = blockEntity.getMetaMachine(); |
| 51 | + if (machine instanceof DataBankMachine dataBank) { |
| 52 | + compoundTag.putLong("energyUsage", dataBank.getEnergyUsage()); |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments