|
| 1 | +package gregtech.integration.hwyla.provider; |
| 2 | + |
| 3 | +import gregtech.api.GTValues; |
| 4 | +import gregtech.api.capability.IQuantumController; |
| 5 | +import gregtech.api.capability.IQuantumStorage; |
| 6 | +import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; |
| 7 | +import gregtech.api.util.GTUtility; |
| 8 | + |
| 9 | +import net.minecraft.client.resources.I18n; |
| 10 | +import net.minecraft.entity.player.EntityPlayerMP; |
| 11 | +import net.minecraft.item.ItemStack; |
| 12 | +import net.minecraft.nbt.NBTTagCompound; |
| 13 | +import net.minecraft.tileentity.TileEntity; |
| 14 | +import net.minecraft.util.math.BlockPos; |
| 15 | +import net.minecraft.util.text.TextFormatting; |
| 16 | +import net.minecraft.world.World; |
| 17 | + |
| 18 | +import mcp.mobius.waila.api.IWailaConfigHandler; |
| 19 | +import mcp.mobius.waila.api.IWailaDataAccessor; |
| 20 | +import mcp.mobius.waila.api.IWailaDataProvider; |
| 21 | +import mcp.mobius.waila.api.IWailaRegistrar; |
| 22 | +import org.jetbrains.annotations.NotNull; |
| 23 | + |
| 24 | +import java.util.List; |
| 25 | + |
| 26 | +public class QuantumStorageProvider implements IWailaDataProvider { |
| 27 | + |
| 28 | + public static final QuantumStorageProvider INSTANCE = new QuantumStorageProvider(); |
| 29 | + |
| 30 | + public void register(@NotNull IWailaRegistrar registrar) { |
| 31 | + registrar.registerBodyProvider(this, IGregTechTileEntity.class); |
| 32 | + registrar.registerNBTProvider(this, IGregTechTileEntity.class); |
| 33 | + registrar.addConfig(GTValues.MOD_NAME, "gregtech.quantum_storage"); |
| 34 | + } |
| 35 | + |
| 36 | + @NotNull |
| 37 | + @Override |
| 38 | + public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, |
| 39 | + BlockPos pos) { |
| 40 | + if (te instanceof IGregTechTileEntity gtte) { |
| 41 | + if (gtte.getMetaTileEntity() instanceof IQuantumStorage<?>storage && |
| 42 | + (storage.getType() == IQuantumStorage.Type.ITEM || |
| 43 | + storage.getType() == IQuantumStorage.Type.FLUID)) { |
| 44 | + var controller = storage.getQuantumController(); |
| 45 | + int status = 0; |
| 46 | + |
| 47 | + if (controller != null) { |
| 48 | + if (controller.isPowered()) { |
| 49 | + status = 1; |
| 50 | + } else { |
| 51 | + status = 2; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + NBTTagCompound subTag = new NBTTagCompound(); |
| 56 | + subTag.setInteger("Connection", status); |
| 57 | + tag.setTag("gregtech.IQuantumStorageController", subTag); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + return tag; |
| 62 | + } |
| 63 | + |
| 64 | + @NotNull |
| 65 | + @Override |
| 66 | + public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWailaDataAccessor accessor, |
| 67 | + IWailaConfigHandler config) { |
| 68 | + if (!config.getConfig("gregtech.quantum_storage") || |
| 69 | + !(accessor.getTileEntity() instanceof IGregTechTileEntity gtte)) { |
| 70 | + return tooltip; |
| 71 | + } |
| 72 | + |
| 73 | + if (gtte.getMetaTileEntity() instanceof IQuantumController controller) { |
| 74 | + String eutText = configureEnergyUsage(controller.getEnergyUsage() / 10); |
| 75 | + if (controller.getCount(IQuantumStorage.Type.ENERGY) == 0) { |
| 76 | + tooltip.add(I18n.format("gregtech.top.quantum_controller.no_hatches")); |
| 77 | + tooltip.add(I18n.format("gregtech.top.energy_required") + eutText); |
| 78 | + } else if (!controller.isPowered()) { |
| 79 | + tooltip.add(I18n.format("gregtech.top.quantum_controller.no_power")); |
| 80 | + tooltip.add(I18n.format("gregtech.top.energy_required") + eutText); |
| 81 | + } else { |
| 82 | + tooltip.add(I18n.format("gregtech.top.energy_consumption") + eutText); |
| 83 | + } |
| 84 | + } else if (gtte.getMetaTileEntity() instanceof IQuantumStorage<?>storage && |
| 85 | + (storage.getType() == IQuantumStorage.Type.ITEM || |
| 86 | + storage.getType() == IQuantumStorage.Type.FLUID)) { |
| 87 | + if (accessor.getNBTData().hasKey("gregtech.IQuantumStorageController")) { |
| 88 | + NBTTagCompound tag = accessor.getNBTData() |
| 89 | + .getCompoundTag("gregtech.IQuantumStorageController"); |
| 90 | + int connection = tag.getInteger("Connection"); |
| 91 | + String status; |
| 92 | + |
| 93 | + switch (connection) { |
| 94 | + case 1 -> status = I18n.format("gregtech.top.quantum_status.powered"); |
| 95 | + case 2 -> status = I18n.format("gregtech.top.quantum_status.connected"); |
| 96 | + default -> status = I18n.format("gregtech.top.quantum_status.disconnected"); |
| 97 | + } |
| 98 | + |
| 99 | + status = I18n.format("gregtech.top.quantum_status.label") + |
| 100 | + status; |
| 101 | + |
| 102 | + tooltip.add(status); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + return tooltip; |
| 107 | + } |
| 108 | + |
| 109 | + public String configureEnergyUsage(long EUs) { |
| 110 | + return TextFormatting.RED.toString() + EUs + " EU/t" + TextFormatting.GREEN + |
| 111 | + " (" + GTValues.VNF[GTUtility.getTierByVoltage(EUs)] + TextFormatting.GREEN + ")"; |
| 112 | + } |
| 113 | +} |
0 commit comments