Skip to content

Commit f6b6b63

Browse files
committed
idea code clean-up
add notification fix number-value-display
1 parent b82ea0f commit f6b6b63

File tree

1,261 files changed

+8746
-8945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,261 files changed

+8746
-8945
lines changed

src/main/java/cn/langya/Client.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import cn.langya.ui.ElementManager;
66
import cn.langya.event.EventManager;
77
import cn.langya.module.ModuleManager;
8+
import cn.langya.ui.notification.NotificationManager;
89
import cn.langya.value.ValueManager;
910
import de.florianmichael.viamcp.ViaMCP;
1011
import lombok.Getter;
@@ -30,6 +31,7 @@ public class Client {
3031
private ValueManager valueManager;
3132
private ConfigManager configManager;
3233
private CommandManager commandManager;
34+
private NotificationManager notificationManager;
3335

3436
/**
3537
* 初始化客户端,设置各个管理器并配置显示标题。
@@ -42,6 +44,7 @@ public void initClient() {
4244
this.valueManager = new ValueManager();
4345
this.configManager = new ConfigManager();
4446
this.commandManager = new CommandManager();
47+
this.notificationManager = new NotificationManager();
4548

4649
initViaMCP();
4750

src/main/java/cn/langya/module/Module.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cn.langya.Client;
44
import cn.langya.Wrapper;
5+
import cn.langya.ui.notification.NotificationType;
56
import cn.langya.utils.ChatUtil;
67
import cn.langya.value.Value;
78
import lombok.Getter;
@@ -42,20 +43,21 @@ public Module(Category category) {
4243
* @param enable 模块是否启用
4344
*/
4445
public void setEnable(boolean enable) {
46+
boolean isNull = mc.thePlayer == null;
4547
// 赋值需要.this
4648
this.enable = enable;
4749
// 获取值不需要.this
4850
if (enable) {
4951
onEnable();
50-
ChatUtil.info(this.name + EnumChatFormatting.GREEN + " Enabled.");
52+
if (!isNull) Client.getInstance().getNotificationManager().addNotification(this.name + EnumChatFormatting.RED + " Enabled.", NotificationType.SUCCESS);
5153
} else {
5254
onDisable();
53-
ChatUtil.info(this.name + EnumChatFormatting.RED + " Disable.");
55+
if (!isNull) Client.getInstance().getNotificationManager().addNotification(this.name + EnumChatFormatting.RED + " Disable.", NotificationType.ERROR);
5456
}
5557

5658
Client.getInstance().getEventManager().registerModule(enable,this);
5759

58-
if (mc.thePlayer != null) mc.theWorld.playSound(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, "random.click", 0.5F, enable ? 0.6F : 0.5F, false);
60+
if (!isNull) mc.theWorld.playSound(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, "random.click", 0.5F, enable ? 0.6F : 0.5F, false);
5961
}
6062

6163
/**
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cn.langya.module.impl.render;
2+
3+
import cn.langya.Client;
4+
import cn.langya.event.annotations.EventTarget;
5+
import cn.langya.event.events.EventRender2D;
6+
import cn.langya.module.Category;
7+
import cn.langya.module.Module;
8+
import cn.langya.ui.font.FontManager;
9+
import cn.langya.ui.notification.NotificationType;
10+
import cn.langya.utils.RenderUtil;
11+
import net.minecraft.client.gui.FontRenderer;
12+
13+
import java.awt.*;
14+
import java.util.List;
15+
16+
/**
17+
* @author LangYa466
18+
* @since 2/27/2025
19+
*/
20+
public class Notification extends Module {
21+
/**
22+
* 构造函数,初始化模块的名称和类别。
23+
*/
24+
public Notification() {
25+
super(Category.Render);
26+
}
27+
28+
@EventTarget
29+
public void onRender2D(EventRender2D event) {
30+
List<cn.langya.ui.notification.Notification> notifications = Client.getInstance().getNotificationManager().getActiveNotifications();
31+
if (notifications.isEmpty()) return;
32+
33+
FontRenderer fontRenderer = FontManager.vivo(20);
34+
int screenWidth = event.getScaledresolution().getScaledWidth();
35+
int screenHeight = event.getScaledresolution().getScaledHeight();
36+
int yOffset = screenHeight - 10; // 从底部开始显示通知
37+
38+
for (cn.langya.ui.notification.Notification notification : notifications) {
39+
String message = notification.getMessage();
40+
NotificationType type = notification.getType();
41+
int width = fontRenderer.getStringWidth(message) + 20;
42+
int height = 20;
43+
44+
// 计算颜色
45+
Color bgColor;
46+
switch (type) {
47+
case SUCCESS: bgColor = new Color(0, 200, 0, 150); break;
48+
case WARNING: bgColor = new Color(255, 165, 0, 150); break;
49+
case ERROR: bgColor = new Color(200, 0, 0, 150); break;
50+
default: bgColor = new Color(0, 0, 0, 150); break;
51+
}
52+
53+
// 背景
54+
RenderUtil.drawRect2(screenWidth - width - 5, yOffset - height, screenWidth - 5, yOffset, bgColor.getRGB());
55+
56+
// 绘制文本
57+
fontRenderer.drawStringWithShadow(message, screenWidth - width, yOffset - height + 6, Color.WHITE.getRGB());
58+
59+
// 递增偏移量
60+
yOffset -= (height + 5);
61+
}
62+
}
63+
}

src/main/java/cn/langya/ui/clickgui/SimpleClickGUI.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import cn.langya.Client;
44
import cn.langya.module.Module;
5-
import cn.langya.ui.font.FontManager;
65
import cn.langya.utils.HoveringUtil;
76
import cn.langya.utils.RenderUtil;
87
import cn.langya.value.Value;
@@ -27,7 +26,6 @@
2726
@Getter
2827
@Setter
2928
public class SimpleClickGUI extends GuiScreen {
30-
3129
private DragWindow dragWindow;
3230
private int scrollOffset = 0;
3331
private static final int MAX_SCROLL = 200;
@@ -123,7 +121,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
123121
double normalizedValue = (current - min) / (max - min);
124122
RenderUtil.drawString(value.getName(), x, y, -1);
125123
RenderUtil.drawColorSlider(x + 100, y + 3, 80, normalizedValue, 1.0, Color.BLUE);
126-
RenderUtil.drawString(String.valueOf(current), x + 190, y, -1);
124+
RenderUtil.drawString(String.format("%.2f", current), x + 190, y, -1);
127125
y += 25;
128126
} else if (value instanceof ColorValue) {
129127
ColorValue colorValue = (ColorValue) value;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cn.langya.ui.notification;
2+
3+
import cn.langya.utils.TimerUtil;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
7+
/**
8+
* 通知类,表示一条消息通知
9+
*/
10+
@Getter
11+
@Setter
12+
public class Notification {
13+
private final String message;
14+
private final NotificationType type;
15+
// 通知显示的持续时间(单位:毫秒)
16+
private final int displayDuration;
17+
// 使用 TimerUtil 来跟踪通知的显示时长
18+
private final TimerUtil timer;
19+
20+
/**
21+
* 构造通知
22+
* @param message 提示信息
23+
* @param type 通知类型
24+
* @param displayDuration 显示时长(毫秒)
25+
*/
26+
public Notification(String message, NotificationType type, int displayDuration) {
27+
this.message = message;
28+
this.type = type;
29+
this.displayDuration = displayDuration;
30+
this.timer = new TimerUtil();
31+
this.timer.reset();
32+
}
33+
/**
34+
* 判断通知是否已过期
35+
* @return true 表示通知已显示超过规定时长,可从列表中移除
36+
*/
37+
public boolean isExpired() {
38+
return timer.hasReached(displayDuration);
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cn.langya.ui.notification;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* 通知管理器,管理所有通知的添加、清理和获取操作
8+
*/
9+
public class NotificationManager {
10+
// 存储当前的通知列表
11+
private final List<Notification> notifications = new ArrayList<>();
12+
13+
/**
14+
* 添加新的通知
15+
* @param notification 要添加的通知
16+
*/
17+
public void addNotification(Notification notification) {
18+
notifications.add(notification);
19+
}
20+
21+
public void addNotification(String message, NotificationType type) {
22+
notifications.add(new Notification(message,type,1500));
23+
}
24+
25+
/**
26+
* 获取当前未过期的通知列表
27+
* 在返回前,会自动清理掉已经过期的通知
28+
* @return 未过期通知的列表
29+
*/
30+
public List<Notification> getActiveNotifications() {
31+
// 移除过期的通知
32+
notifications.removeIf(Notification::isExpired);
33+
return new ArrayList<>(notifications);
34+
}
35+
36+
/**
37+
* 清空所有通知
38+
*/
39+
public void clearNotifications() {
40+
notifications.clear();
41+
}
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cn.langya.ui.notification;
2+
3+
/**
4+
* 通知类型枚举,可根据需要添加其他类型
5+
*/
6+
public enum NotificationType {
7+
INFO,
8+
SUCCESS,
9+
WARNING,
10+
ERROR
11+
}

src/main/java/cn/langya/utils/RenderUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static int drawStringWithShadow(String text, int x, int y, int color) {
6969
return FontManager.vivo(18).drawStringWithShadow(text, x, y, color);
7070
}
7171

72-
public static void drawRect(double left, double top, double right, double bottom, int color) {
72+
public static void drawRect2(double left, double top, double right, double bottom, int color) {
7373
Tessellator tessellator = Tessellator.getInstance();
7474
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
7575

@@ -104,12 +104,12 @@ public static void drawColorSlider(int x, int y, int width, double value, double
104104
int barWidth = (int) (width * (value / max));
105105

106106
// 背景
107-
drawRect(x, y, width, 5, new Color(50, 50, 50).getRGB());
107+
drawRect2(x, y, width, 5, new Color(50, 50, 50).getRGB());
108108

109109
// 进度条
110-
drawRect(x, y, barWidth, 5, color.getRGB());
110+
drawRect2(x, y, barWidth, 5, color.getRGB());
111111

112112
// 滑块
113-
drawRect(x + barWidth - 2, y - 2, 4, 9, Color.WHITE.getRGB());
113+
drawRect2(x + barWidth - 2, y - 2, 4, 9, Color.WHITE.getRGB());
114114
}
115115
}

src/main/java/de/florianmichael/viamcp/fixes/FixedSoundEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ else if (!playerIn.canPlayerEdit(pos, side, stack))
8484
{
8585
return false;
8686
}
87-
else if (worldIn.canBlockBePlaced(iblock.getBlock(), pos, false, side, (Entity)null, stack))
87+
else if (worldIn.canBlockBePlaced(iblock.getBlock(), pos, false, side, null, stack))
8888
{
8989
int i = iblock.getMetadata(stack.getMetadata());
9090
IBlockState iblockstate1 = iblock.getBlock().onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);
@@ -106,7 +106,7 @@ else if (worldIn.canBlockBePlaced(iblock.getBlock(), pos, false, side, (Entity)n
106106
}
107107
else
108108
{
109-
worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), iblock.getBlock().stepSound.getPlaceSound(), (iblock.getBlock().stepSound.getVolume() + 1.0F) / 2.0F, iblock.getBlock().stepSound.getFrequency() * 0.8F);
109+
worldIn.playSoundEffect((float)pos.getX() + 0.5F, (float)pos.getY() + 0.5F, (float)pos.getZ() + 0.5F, iblock.getBlock().stepSound.getPlaceSound(), (iblock.getBlock().stepSound.getVolume() + 1.0F) / 2.0F, iblock.getBlock().stepSound.getFrequency() * 0.8F);
110110
}
111111

112112
--stack.stackSize;

0 commit comments

Comments
 (0)