This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CubeWhy
committed
Jul 1, 2023
1 parent
cdd20b2
commit 5916ca3
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/org/cubewhy/lunarcn/event/events/JoinServerEvent.java
This file contains 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,26 @@ | ||
package org.cubewhy.lunarcn.event.events; | ||
|
||
import net.minecraft.client.multiplayer.ServerData; | ||
import org.cubewhy.lunarcn.event.Event; | ||
|
||
public class JoinServerEvent extends Event { | ||
private final String ip; | ||
private final int port; | ||
|
||
public JoinServerEvent(String ip, int port) { | ||
this.ip = ip; | ||
this.port = port; | ||
} | ||
|
||
public String getIp() { | ||
return ip; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
public String getAddress() { | ||
return ip + ":" + port; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/cubewhy/lunarcn/injection/forge/mixins/gui/MixinGuiConnecting.java
This file contains 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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
package org.cubewhy.lunarcn.injection.forge.mixins.gui; | ||
|
||
import net.minecraft.client.multiplayer.GuiConnecting; | ||
import net.minecraft.client.multiplayer.ServerData; | ||
import org.cubewhy.lunarcn.event.events.JoinServerEvent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(GuiConnecting.class) | ||
public class MixinGuiConnecting { | ||
@Inject(method = "connect", at = @At("RETURN")) | ||
private void connect(String ip, int port, CallbackInfo ci) { | ||
new JoinServerEvent(ip, port).call(); // 加入服务器事件 | ||
} | ||
} |
This file contains 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
97 changes: 97 additions & 0 deletions
97
src/main/kotlin/org/cubewhy/lunarcn/module/modules/render/GameInfo.kt
This file contains 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,97 @@ | ||
package org.cubewhy.lunarcn.module.modules.render | ||
|
||
import net.minecraft.client.renderer.GlStateManager | ||
import org.cubewhy.lunarcn.event.EventTarget | ||
import org.cubewhy.lunarcn.event.events.JoinServerEvent | ||
import org.cubewhy.lunarcn.gui.hud.ScreenPosition | ||
import org.cubewhy.lunarcn.module.ModuleCategory | ||
import org.cubewhy.lunarcn.module.ModuleDraggable | ||
import org.cubewhy.lunarcn.module.ModuleInfo | ||
import org.cubewhy.lunarcn.utils.MSTimer | ||
import org.cubewhy.lunarcn.utils.RenderUtils | ||
import java.awt.Color | ||
|
||
@ModuleInfo(name = "GameInfo", document = "Show current session", category = ModuleCategory.RENDER) | ||
class GameInfo : ModuleDraggable() { | ||
private var position: ScreenPosition? = null; | ||
private val timer: MSTimer = MSTimer() | ||
|
||
override fun save(position: ScreenPosition) { | ||
this.position = position | ||
} | ||
|
||
override fun load(): ScreenPosition { | ||
if (this.position == null) { | ||
this.position = ScreenPosition.fromRelativePosition(0.5, 0.5); | ||
} | ||
return this.position!! | ||
} | ||
|
||
override fun getWidth(): Int { | ||
return 300 | ||
} | ||
|
||
override fun getHeight(): Int { | ||
return 50 | ||
} | ||
|
||
override fun render(position: ScreenPosition?) { | ||
if (timer.time == -1L) { | ||
this.timer.reset() | ||
} | ||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F) | ||
val x = this.position!!.absoluteX | ||
val y = this.position!!.absoluteY | ||
// 绘制背景 | ||
RenderUtils.drawRoundedRect( | ||
x, y, | ||
width, height, 2, | ||
Color(0, 0, 0, 30) | ||
) | ||
// 绘制文字 | ||
RenderUtils.drawString( | ||
"Player: " + mc.session.username, | ||
x + 10, | ||
y + 10, | ||
Color(255, 255, 255, 50).rgb, | ||
true | ||
) | ||
RenderUtils.drawString( | ||
"Play time: " + formatTime(timer.timePassed()), | ||
x + 10, | ||
y + mc.fontRendererObj.FONT_HEIGHT * 2, | ||
Color(255, 255, 255, 50).rgb, | ||
true | ||
) | ||
RenderUtils.drawString( | ||
"Server IP: " + getServerIp(), | ||
x + 10, | ||
y + mc.fontRendererObj.FONT_HEIGHT * 3, | ||
Color(255, 255, 255, 50).rgb, | ||
true | ||
) | ||
} | ||
|
||
private fun getServerIp(): String { | ||
val serverIp = if (mc.currentServerData == null) { | ||
"SignalPlayer" | ||
} else { | ||
mc.currentServerData.serverIP | ||
} | ||
return serverIp | ||
} | ||
|
||
private fun formatTime(time: Long): String { | ||
val realTime = time / 1000 | ||
val hours = realTime / 3600 | ||
val minutes = realTime % 3600 / 60 | ||
val seconds = realTime % 3600 % 60 | ||
|
||
return "${hours}:${minutes}:${seconds}" | ||
} | ||
|
||
@EventTarget | ||
fun onJoinServer(e: JoinServerEvent) { | ||
this.timer.reset() | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.