-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Show modflared indicator in server list #96
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
hattapauzi
wants to merge
4
commits into
HttpRafa:forge/1.12.2
Choose a base branch
from
hattapauzi:forge/1.12.2
base: forge/1.12.2
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6d7a2d6
feat: Show modflared indicator in server list
hattapauzi e2f8107
fix: Reset GL color before drawing indicator
hattapauzi 56f1774
fix: Use localized tunnel text with fallbacks
hattapauzi e2bbe4b
chore: Remove legacy label from Forge version
hattapauzi 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
87 changes: 87 additions & 0 deletions
87
src/main/java/dev/httxrafa/modflared/mixin/client/ServerListEntryNormalMixin.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,87 @@ | ||
| package dev.httxrafa.modflared.mixin.client; | ||
|
|
||
| import dev.httxrafa.modflared.Modflared; | ||
| import dev.httxrafa.modflared.interfaces.mixin.IServerData; | ||
| import dev.httxrafa.modflared.tunnel.TunnelStatus; | ||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.client.gui.Gui; | ||
| import net.minecraft.client.gui.GuiMultiplayer; | ||
| import net.minecraft.client.gui.ServerListEntryNormal; | ||
| import net.minecraft.client.multiplayer.ServerData; | ||
| import net.minecraft.client.renderer.GlStateManager; | ||
| import net.minecraft.client.resources.I18n; | ||
| import net.minecraft.util.ResourceLocation; | ||
| import org.spongepowered.asm.mixin.Final; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.Unique; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
|
||
| @Mixin(ServerListEntryNormal.class) | ||
| public abstract class ServerListEntryNormalMixin { | ||
|
|
||
| @Shadow | ||
| @Final | ||
| private GuiMultiplayer owner; | ||
|
|
||
| @Shadow | ||
| @Final | ||
| private ServerData server; | ||
|
|
||
| @Unique | ||
| private static final ResourceLocation MODFLARED_INDICATOR_TEXTURE = new ResourceLocation( | ||
| Modflared.MOD_ID, | ||
| "textures/gui/sprites/icon/indicator.png" | ||
| ); | ||
|
|
||
| @Unique | ||
| private static final int MODFLARED_INDICATOR_SIZE = 10; | ||
|
|
||
| @Unique | ||
| private static final int MODFLARED_INDICATOR_RIGHT_OFFSET = 28; | ||
|
|
||
| @Unique | ||
| private static final String MODFLARED_INDICATOR_TOOLTIP_KEY = "gui.multiplayer.tunnel.status.0"; | ||
|
|
||
| @Unique | ||
| private static final String MODFLARED_INDICATOR_TOOLTIP_FALLBACK = "Modflared in use"; | ||
|
|
||
| @Inject(method = "drawEntry", at = @At("TAIL")) | ||
| private void modflared$drawTunnelIndicator(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected, float partialTicks, CallbackInfo callbackInfo) { | ||
| TunnelStatus tunnelStatus = ((IServerData) this.server).getTunnelStatus(); | ||
| if (tunnelStatus == null || tunnelStatus.getState() != TunnelStatus.State.USE) { | ||
| return; | ||
| } | ||
|
|
||
| int indicatorX = x + listWidth - MODFLARED_INDICATOR_RIGHT_OFFSET; | ||
| int indicatorY = y + 11; | ||
|
|
||
| GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); | ||
| Minecraft.getMinecraft().getTextureManager().bindTexture(MODFLARED_INDICATOR_TEXTURE); | ||
| Gui.drawModalRectWithCustomSizedTexture( | ||
| indicatorX, | ||
| indicatorY, | ||
| 0.0F, | ||
| 0.0F, | ||
| MODFLARED_INDICATOR_SIZE, | ||
| MODFLARED_INDICATOR_SIZE, | ||
| MODFLARED_INDICATOR_SIZE, | ||
| MODFLARED_INDICATOR_SIZE | ||
| ); | ||
|
|
||
| if (mouseX >= indicatorX && mouseX <= indicatorX + MODFLARED_INDICATOR_SIZE && mouseY >= indicatorY && mouseY <= indicatorY + MODFLARED_INDICATOR_SIZE) { | ||
| this.owner.setHoveringText(modflared$translate(MODFLARED_INDICATOR_TOOLTIP_KEY, MODFLARED_INDICATOR_TOOLTIP_FALLBACK)); | ||
| } | ||
| } | ||
|
|
||
| @Unique | ||
| private static String modflared$translate(String key, String fallback) { | ||
| String translated = I18n.format(key); | ||
| if (translated == null || translated.equals(key)) { | ||
| return fallback; | ||
| } | ||
|
hattapauzi marked this conversation as resolved.
|
||
| return translated; | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.