Skip to content

Commit cc280d9

Browse files
committed
Updated EnchantmentHandler and UI-Utils
1 parent 70180ac commit cc280d9

File tree

11 files changed

+3120
-3058
lines changed

11 files changed

+3120
-3058
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ Reports number of waypoints changed.
316316
### EnchantmentHandler
317317
- Displays an inventory overlay for chests containing enchanted items, listing each item's slot number, enchantments, and providing quick-take options (single or by category).
318318
- Renders on top of the vanilla screen darkening, stays aligned beside the container and has an adjustable size and font scaling
319+
- Draggable position with mouse
319320
- Works with books, potions and gear and will separate them in the list by category and type
320321

321322
![Chest](https://i.imgur.com/0TdpYkM.png)

src/main/java/net/wurstclient/hacks/EnchantmentHandlerHack.java

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public final class EnchantmentHandlerHack extends Hack
6868
private static final int ACTION_HOVER_COLOR = 0xFFB6E1FF;
6969
private static final long HOVER_SCROLL_DELAY_MS = 400;
7070
private static final double HOVER_SCROLL_PAUSE = 32.0;
71+
private static final int DRAG_BAR_HEIGHT = 28;
7172

7273
private final List<AbstractEntry> allEntries = new ArrayList<>();
7374
private final Map<GearCategory, List<GearEntry>> gearGroupedEntries =
@@ -97,12 +98,6 @@ public final class EnchantmentHandlerHack extends Hack
9798
private final SliderSetting boxHeight = new SliderSetting("Box height",
9899
"Panel height in pixels.\n0 = match the container height.", 0, 0, 320,
99100
2, ValueDisplay.INTEGER);
100-
private final SliderSetting offsetX = new SliderSetting("Horizontal offset",
101-
"Moves the panel left/right relative to the container.", 0, -300, 300,
102-
2, ValueDisplay.INTEGER);
103-
private final SliderSetting offsetY = new SliderSetting("Vertical offset",
104-
"Moves the panel up/down relative to the container.", 0, -200, 200, 2,
105-
ValueDisplay.INTEGER);
106101
private final SliderSetting textScale = new SliderSetting("Text scale", 0.7,
107102
0.5, 1.25, 0.05, ValueDisplay.DECIMAL);
108103
private final SliderSetting hoverScrollSpeed = new SliderSetting(
@@ -120,6 +115,10 @@ public final class EnchantmentHandlerHack extends Hack
120115
private int panelY;
121116
private int panelWidth;
122117
private int panelHeight;
118+
private boolean customPosition;
119+
private boolean panelDragging;
120+
private int dragOffsetX;
121+
private int dragOffsetY;
123122
private boolean lastRenderActive;
124123
private boolean needsRescan = true;
125124
private int contentHeight;
@@ -133,8 +132,6 @@ public EnchantmentHandlerHack()
133132

134133
addSetting(boxWidth);
135134
addSetting(boxHeight);
136-
addSetting(offsetX);
137-
addSetting(offsetY);
138135
addSetting(textScale);
139136
addSetting(hoverScrollSpeed);
140137
addSetting(includePlayerInventory);
@@ -182,6 +179,10 @@ protected void onDisable()
182179
hitboxes.clear();
183180
hoveredSlotId = -1;
184181
hoverStartMs = 0L;
182+
customPosition = false;
183+
panelDragging = false;
184+
dragOffsetX = 0;
185+
dragOffsetY = 0;
185186
}
186187

187188
public void renderOnHandledScreen(AbstractContainerScreen<?> screen,
@@ -220,9 +221,22 @@ public void renderOnHandledScreen(AbstractContainerScreen<?> screen,
220221
panelHeight = Mth.clamp(configuredHeight, 60,
221222
Math.max(60, windowHeight - 10));
222223

223-
panelY = accessor.getY() + offsetY.getValueI();
224-
panelX =
225-
accessor.getX() - panelWidth - PANEL_PADDING + offsetX.getValueI();
224+
int defaultX = accessor.getX() - panelWidth - PANEL_PADDING;
225+
int defaultY = accessor.getY();
226+
if(!customPosition)
227+
{
228+
panelX = defaultX;
229+
panelY = defaultY;
230+
}
231+
232+
if(panelDragging)
233+
{
234+
double scaledMouseX = getScaledMouseX(context);
235+
double scaledMouseY = getScaledMouseY(context);
236+
panelX = (int)Math.round(scaledMouseX - dragOffsetX);
237+
panelY = (int)Math.round(scaledMouseY - dragOffsetY);
238+
customPosition = true;
239+
}
226240

227241
panelX =
228242
Mth.clamp(panelX, 2 - panelWidth, windowWidth - panelWidth - 2);
@@ -238,6 +252,12 @@ public boolean handleMouseClick(AbstractContainerScreen<?> screen,
238252
if(!lastRenderActive)
239253
return false;
240254

255+
if(button == 0 && isInsideDragBar(mouseX, mouseY))
256+
{
257+
startPanelDrag(mouseX, mouseY);
258+
return true;
259+
}
260+
241261
if(button != 0 && button != 1)
242262
return isInsidePanel(mouseX, mouseY);
243263

@@ -301,6 +321,18 @@ else if(hitbox.entry instanceof PotionEntry potion)
301321
return isInsidePanel(mouseX, mouseY);
302322
}
303323

324+
public boolean handleMouseRelease(AbstractContainerScreen<?> screen,
325+
double mouseX, double mouseY, int button)
326+
{
327+
if(panelDragging && button == 0)
328+
{
329+
panelDragging = false;
330+
return true;
331+
}
332+
333+
return false;
334+
}
335+
304336
public boolean handleMouseScroll(AbstractContainerScreen<?> screen,
305337
double mouseX, double mouseY, double amount)
306338
{
@@ -325,6 +357,20 @@ private boolean isInsidePanel(double mouseX, double mouseY)
325357
&& mouseY >= panelY && mouseY <= panelY + panelHeight;
326358
}
327359

360+
private boolean isInsideDragBar(double mouseX, double mouseY)
361+
{
362+
return mouseX >= panelX && mouseX <= panelX + panelWidth
363+
&& mouseY >= panelY && mouseY <= panelY + DRAG_BAR_HEIGHT;
364+
}
365+
366+
private void startPanelDrag(double mouseX, double mouseY)
367+
{
368+
panelDragging = true;
369+
dragOffsetX = (int)Math.round(mouseX - panelX);
370+
dragOffsetY = (int)Math.round(mouseY - panelY);
371+
customPosition = true;
372+
}
373+
328374
private void renderOverlay(GuiGraphics context)
329375
{
330376
hitboxes.clear();

src/main/java/net/wurstclient/mixin/HandledScreenMixin.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ else if(slot != null)
139139

140140
if(WurstClient.INSTANCE.getGui().handlePinnedMouseRelease(context.x(),
141141
context.y(), context.button()))
142+
{
143+
cir.setReturnValue(true);
144+
cir.cancel();
145+
return;
146+
}
147+
148+
EnchantmentHandlerHack enchantHack =
149+
WurstClient.INSTANCE.getHax().enchantmentHandlerHack;
150+
if(enchantHack != null && enchantHack.isEnabled()
151+
&& enchantHack.handleMouseRelease(
152+
(AbstractContainerScreen<?>)(Object)this, context.x(),
153+
context.y(), context.button()))
142154
{
143155
cir.setReturnValue(true);
144156
cir.cancel();

src/main/java/net/wurstclient/mixin/ui_utils/UiUtilsAbstractContainerScreenMixin.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,11 +703,14 @@ private void sendButtonClick()
703703
@Inject(at = @At("HEAD"), method = "removed()V", cancellable = true)
704704
private void onRemoved(CallbackInfo ci)
705705
{
706-
if(!UiUtilsState.skipNextContainerRemoval)
706+
if(UiUtilsState.skipNextContainerRemoval)
707+
{
708+
UiUtilsState.skipNextContainerRemoval = false;
709+
ci.cancel();
707710
return;
711+
}
708712

709-
UiUtilsState.skipNextContainerRemoval = false;
710-
ci.cancel();
713+
fabricateOverlayInitialized = false;
711714
}
712715

713716
}
Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
[
2-
"AntiBlast",
3-
"AntiBlind",
4-
"AntiCheatDetect",
5-
"AntiDrop",
6-
"AntiEntityPush",
7-
"AntiKnockback",
8-
"AntiWaterPush",
9-
"AutoDrop",
10-
"AutoReconnect",
11-
"AutoRespawn",
12-
"AutoTool",
13-
"AutoTotem",
14-
"BeaconExploit",
15-
"BedESP",
16-
"BedrockEscape",
17-
"Breadcrumbs",
18-
"CheatDetector",
19-
"ChestESP",
20-
"CoordLogger",
21-
"Criticals",
22-
"DamageDetect",
23-
"Durability HUD",
24-
"ElytraFlight",
25-
"EnchantmentHandler",
26-
"Flight",
27-
"Fullbright",
28-
"HandNoClip",
29-
"HealthTags",
30-
"ItemESP",
31-
"ItemHandler",
32-
"LavaWaterESP",
33-
"LogoutSpots",
34-
"MaceDMG",
35-
"MobESP",
36-
"NameTags",
37-
"NoBackground",
38-
"NoFall",
39-
"NoFog",
40-
"NoLevitation",
41-
"NoOverlay",
42-
"NoShieldOverlay",
43-
"NoSlowdown",
44-
"NoWeather",
45-
"NoWeb",
46-
"Outreach",
47-
"PacketRate",
48-
"PearlESP",
49-
"PlayerESP",
50-
"PortalESP",
51-
"PortalGUI",
52-
"QuickShulker",
53-
"Reach",
54-
"SignESP",
55-
"SignFramePT",
56-
"SnowShoe",
57-
"SpearAssist",
58-
"SusNoMore",
59-
"TridentESP",
60-
"TrueSight",
61-
"WardenESP",
62-
"Waypoints",
63-
"WorkstationESP",
64-
"XCarry"
65-
]
1+
[
2+
"AntiBlast",
3+
"AntiBlind",
4+
"AntiCheatDetect",
5+
"AntiDrop",
6+
"AntiEntityPush",
7+
"AntiKnockback",
8+
"AntiWaterPush",
9+
"AutoDrop",
10+
"AutoReconnect",
11+
"AutoRespawn",
12+
"AutoTool",
13+
"AutoTotem",
14+
"BeaconExploit",
15+
"BedESP",
16+
"BedrockEscape",
17+
"Breadcrumbs",
18+
"CheatDetector",
19+
"ChestESP",
20+
"CoordLogger",
21+
"Criticals",
22+
"DamageDetect",
23+
"Durability HUD",
24+
"ElytraFlight",
25+
"EnchantmentHandler",
26+
"Flight",
27+
"Fullbright",
28+
"HandNoClip",
29+
"HealthTags",
30+
"ItemESP",
31+
"ItemHandler",
32+
"LavaWaterESP",
33+
"LogoutSpots",
34+
"MaceDMG",
35+
"MobESP",
36+
"NameTags",
37+
"NoBackground",
38+
"NoFall",
39+
"NoFog",
40+
"NoLevitation",
41+
"NoOverlay",
42+
"NoShieldOverlay",
43+
"NoSlowdown",
44+
"NoWeather",
45+
"NoWeb",
46+
"Outreach",
47+
"PacketRate",
48+
"PearlESP",
49+
"PlayerESP",
50+
"PortalESP",
51+
"PortalGUI",
52+
"QuickShulker",
53+
"Reach",
54+
"SignESP",
55+
"SignFramePT",
56+
"SnowShoe",
57+
"SpearAssist",
58+
"SusNoMore",
59+
"TridentESP",
60+
"TrueSight",
61+
"WardenESP",
62+
"Waypoints",
63+
"WorkstationESP",
64+
"XCarry"
65+
]
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
[
2-
"AutoTotem",
3-
"BedESP",
4-
"Breadcrumbs",
5-
"ChestESP",
6-
"Flight",
7-
"HandNoClip",
8-
"ItemESP",
9-
"LavaWaterESP",
10-
"MobESP",
11-
"MobSearch",
12-
"NoFall",
13-
"NoShieldOverlay",
14-
"OpenWaterESP",
15-
"PlayerESP",
16-
"PortalESP",
17-
"RedstoneESP",
18-
"Search",
19-
"SignESP",
20-
"Waypoints",
21-
"X-Ray"
22-
]
1+
[
2+
"AutoTotem",
3+
"BedESP",
4+
"Breadcrumbs",
5+
"ChestESP",
6+
"Flight",
7+
"HandNoClip",
8+
"ItemESP",
9+
"LavaWaterESP",
10+
"MobESP",
11+
"MobSearch",
12+
"NoFall",
13+
"NoShieldOverlay",
14+
"OpenWaterESP",
15+
"PlayerESP",
16+
"PortalESP",
17+
"RedstoneESP",
18+
"Search",
19+
"SignESP",
20+
"Waypoints",
21+
"X-Ray"
22+
]

0 commit comments

Comments
 (0)