-
Notifications
You must be signed in to change notification settings - Fork 204
Show required energy in Quantum controller when out of power #2707
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
113 changes: 113 additions & 0 deletions
113
src/main/java/gregtech/integration/hwyla/provider/QuantumStorageProvider.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,113 @@ | ||
| package gregtech.integration.hwyla.provider; | ||
|
|
||
| import gregtech.api.GTValues; | ||
| import gregtech.api.capability.IQuantumController; | ||
| import gregtech.api.capability.IQuantumStorage; | ||
| import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; | ||
| import gregtech.api.util.GTUtility; | ||
|
|
||
| import net.minecraft.client.resources.I18n; | ||
| import net.minecraft.entity.player.EntityPlayerMP; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.nbt.NBTTagCompound; | ||
| import net.minecraft.tileentity.TileEntity; | ||
| import net.minecraft.util.math.BlockPos; | ||
| import net.minecraft.util.text.TextFormatting; | ||
| import net.minecraft.world.World; | ||
|
|
||
| import mcp.mobius.waila.api.IWailaConfigHandler; | ||
| import mcp.mobius.waila.api.IWailaDataAccessor; | ||
| import mcp.mobius.waila.api.IWailaDataProvider; | ||
| import mcp.mobius.waila.api.IWailaRegistrar; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class QuantumStorageProvider implements IWailaDataProvider { | ||
|
|
||
| public static final QuantumStorageProvider INSTANCE = new QuantumStorageProvider(); | ||
|
|
||
| public void register(@NotNull IWailaRegistrar registrar) { | ||
| registrar.registerBodyProvider(this, IGregTechTileEntity.class); | ||
| registrar.registerNBTProvider(this, IGregTechTileEntity.class); | ||
| registrar.addConfig(GTValues.MOD_NAME, "gregtech.quantum_storage"); | ||
| } | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, | ||
| BlockPos pos) { | ||
| if (te instanceof IGregTechTileEntity gtte) { | ||
| if (gtte.getMetaTileEntity() instanceof IQuantumStorage<?>storage && | ||
| (storage.getType() == IQuantumStorage.Type.ITEM || | ||
| storage.getType() == IQuantumStorage.Type.FLUID)) { | ||
| var controller = storage.getQuantumController(); | ||
| int status = 0; | ||
|
|
||
| if (controller != null) { | ||
| if (controller.isPowered()) { | ||
| status = 1; | ||
| } else { | ||
| status = 2; | ||
| } | ||
| } | ||
|
|
||
| NBTTagCompound subTag = new NBTTagCompound(); | ||
| subTag.setInteger("Connection", status); | ||
| tag.setTag("gregtech.IQuantumStorageController", subTag); | ||
| } | ||
| } | ||
|
|
||
| return tag; | ||
| } | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWailaDataAccessor accessor, | ||
| IWailaConfigHandler config) { | ||
| if (!config.getConfig("gregtech.quantum_storage") || | ||
| !(accessor.getTileEntity() instanceof IGregTechTileEntity gtte)) { | ||
| return tooltip; | ||
| } | ||
|
|
||
| if (gtte.getMetaTileEntity() instanceof IQuantumController controller) { | ||
| String eutText = configureEnergyUsage(controller.getEnergyUsage() / 10); | ||
| if (controller.getCount(IQuantumStorage.Type.ENERGY) == 0) { | ||
| tooltip.add(I18n.format("gregtech.top.quantum_controller.no_hatches")); | ||
| tooltip.add(I18n.format("gregtech.top.energy_required") + eutText); | ||
| } else if (!controller.isPowered()) { | ||
| tooltip.add(I18n.format("gregtech.top.quantum_controller.no_power")); | ||
| tooltip.add(I18n.format("gregtech.top.energy_required") + eutText); | ||
| } else { | ||
| tooltip.add(I18n.format("gregtech.top.energy_consumption") + eutText); | ||
| } | ||
| } else if (gtte.getMetaTileEntity() instanceof IQuantumStorage<?>storage && | ||
| (storage.getType() == IQuantumStorage.Type.ITEM || | ||
| storage.getType() == IQuantumStorage.Type.FLUID)) { | ||
| if (accessor.getNBTData().hasKey("gregtech.IQuantumStorageController")) { | ||
| NBTTagCompound tag = accessor.getNBTData() | ||
| .getCompoundTag("gregtech.IQuantumStorageController"); | ||
| int connection = tag.getInteger("Connection"); | ||
| String status; | ||
|
|
||
| switch (connection) { | ||
| case 1 -> status = I18n.format("gregtech.top.quantum_status.powered"); | ||
| case 2 -> status = I18n.format("gregtech.top.quantum_status.connected"); | ||
| default -> status = I18n.format("gregtech.top.quantum_status.disconnected"); | ||
| } | ||
|
|
||
| status = I18n.format("gregtech.top.quantum_status.label") + | ||
| status; | ||
|
|
||
| tooltip.add(status); | ||
| } | ||
| } | ||
|
|
||
| return tooltip; | ||
| } | ||
|
|
||
| public String configureEnergyUsage(long EUs) { | ||
| return TextFormatting.RED.toString() + EUs + " EU/t" + TextFormatting.GREEN + | ||
| " (" + GTValues.VNF[GTUtility.getTierByVoltage(EUs)] + TextFormatting.GREEN + ")"; | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is purely an import formatting thing, but
provider.*seems a lot better than listing out basically every class in that package.