-
Notifications
You must be signed in to change notification settings - Fork 328
Jade battery provider #4317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zetrock1
wants to merge
9
commits into
GregTechCEu:1.20.1
Choose a base branch
from
zetrock1:jade-battery-provider
base: 1.20.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Jade battery provider #4317
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2da88c2
add battery view (only that it has batteries)
zetrock1 93866a3
jade support for battery info displays in chargerMachine and batteryB…
zetrock1 a0ae1eb
Merge branch '1.20.1' into jade-battery-provider
zetrock1 2a8eade
add to IntegrationLang
zetrock1 fe5a395
more translatable
zetrock1 0e2a352
more readable
zetrock1 375a8c7
Merge branch '1.20.1' into jade-battery-provider
zetrock1 898c541
easier now
zetrock1 0a97ba9
Merge branch '1.20.1' into jade-battery-provider
zetrock1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
129 changes: 129 additions & 0 deletions
129
...main/java/com/gregtechceu/gtceu/integration/jade/provider/BatteryStorageInfoProvider.java
This file contains hidden or 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,129 @@ | ||
| 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 java.math.BigInteger; | ||
|
|
||
| import static com.gregtechceu.gtceu.utils.FormattingUtil.DECIMAL_FORMAT_SIC_2F; | ||
|
|
||
| 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", formatEnergy(changed, 100000))); | ||
| if (changed > 0) { | ||
| iTooltip.add(Component | ||
| .translatable("gtceu.jade.remaining_charge_time", | ||
| getStringRemainTime((capacity - stored) / changed))); | ||
| } else if (changed < 0) { | ||
| 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 " + formatEnergy(item.getCharge(), 100000) + | ||
| " / " + formatEnergy(item.getMaxCharge(), 100000) + " EU")); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private String getStringRemainTime(long time) { | ||
| 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", formatEnergy(time, 10000)).getString() + " " + s; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| String formatEnergy(long energy, long trueshold) { | ||
| if (energy >= trueshold) return DECIMAL_FORMAT_SIC_2F.format(BigInteger.valueOf(energy)); | ||
| else return "" + energy; | ||
| } | ||
|
|
||
| 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"); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.