Skip to content

Commit 58f388c

Browse files
committed
Updated ItemHandler
1 parent 749136d commit 58f388c

3 files changed

Lines changed: 144 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ Reports number of waypoints changed.
391391
- Prevents push back from TNT, creeper explosions, respawn anchors, crystals, wither skulls, wither spawn explosions, ghast fireballs, breeze gusts (and wind charges) and other custom plugins/entities that use explosion physics.
392392

393393
### ItemHandler
394-
- Jade-style Popup HUD and full GUI that lists nearby dropped items grouped by item ID with aggregated counts (With optional registry IDs).
394+
- Jade-style Popup HUD and full GUI that lists nearby dropped items, items in item frames or worn by mobs grouped by item ID with aggregated counts (with optional registry IDs).
395395
- Able to select or reject which item/s to pick up when moving over them:
396396
- Pick: reject (drop) everything except the selected types (only selected types will be picked up).
397397
- Reject: reject the selected types and drop them.
@@ -402,7 +402,7 @@ Reports number of waypoints changed.
402402
- Toggle to adhere to the ItemESP ignored list (Including a link to edit the list)
403403
- Adjustable distance for item detection
404404
- Adjustable font scale setting (scales text and popup icon size)
405-
- Adjustable Popup HUD display offset X/Y
405+
- Adjustable popup HUD display offset X/Y or simply click and drag to reposition (when in inventory or chest)
406406
- Detects XP Orbs and shows the exact XP each orb will give
407407
- Optionally detects items held or worn by mobs (Item count will be for all mobs in the area)
408408
- Can also filter out default mob items to prevent spam

src/main/java/net/wurstclient/hacks/itemhandler/ItemHandlerHack.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.minecraft.world.entity.player.Player;
3232
import net.minecraft.world.entity.HumanoidArm;
3333
import net.minecraft.world.entity.decoration.ArmorStand;
34+
import net.minecraft.world.entity.decoration.ItemFrame;
3435
import net.minecraft.world.entity.EquipmentSlot;
3536
import net.minecraft.world.InteractionHand;
3637
import net.minecraft.world.item.ItemStack;
@@ -510,6 +511,10 @@ private void scanNearbyItems()
510511
player.getBoundingBox().inflate((float)scanRadius),
511512
o -> o != null && o.isAlive() && !o.isRemoved());
512513

514+
List<ItemFrame> foundFrames = MC.level.getEntitiesOfClass(
515+
ItemFrame.class, player.getBoundingBox().inflate((float)scanRadius),
516+
this::shouldTrackItemFrame);
517+
513518
trackedItems.clear();
514519
for(ItemEntity entity : found)
515520
{
@@ -532,6 +537,15 @@ private void scanNearbyItems()
532537
distance, orb.position(), SourceType.XP_ORB, null));
533538
}
534539

540+
for(ItemFrame frame : foundFrames)
541+
{
542+
ItemStack stack = frame.getItem().copy();
543+
double distance = frame.distanceTo(player);
544+
trackedItems
545+
.add(new GroundItem(frame.getId(), frame.getUUID(), stack,
546+
distance, frame.position(), SourceType.ITEM_FRAME, null));
547+
}
548+
535549
if(includeMobEquipment.isChecked())
536550
addMobEquipmentItems(player, scanRadius);
537551

@@ -645,6 +659,16 @@ private boolean shouldTrack(ItemEntity entity)
645659
&& !entity.getItem().isEmpty();
646660
}
647661

662+
private boolean shouldTrackItemFrame(ItemFrame frame)
663+
{
664+
if(frame == null || !frame.isAlive() || frame.isRemoved())
665+
return false;
666+
ItemStack stack = frame.getItem();
667+
if(stack == null || stack.isEmpty())
668+
return false;
669+
return !isIgnoredByItemEsp(stack);
670+
}
671+
648672
private boolean shouldTrackMobEquipment(ItemStack stack)
649673
{
650674
if(stack == null || stack.isEmpty())
@@ -1004,6 +1028,32 @@ public int getHudOffsetY()
10041028
return hudOffsetY.getValueI();
10051029
}
10061030

1031+
public int getHudOffsetMinX()
1032+
{
1033+
return (int)hudOffsetX.getMinimum();
1034+
}
1035+
1036+
public int getHudOffsetMaxX()
1037+
{
1038+
return (int)hudOffsetX.getMaximum();
1039+
}
1040+
1041+
public int getHudOffsetMinY()
1042+
{
1043+
return (int)hudOffsetY.getMinimum();
1044+
}
1045+
1046+
public int getHudOffsetMaxY()
1047+
{
1048+
return (int)hudOffsetY.getMaximum();
1049+
}
1050+
1051+
public void setHudOffsets(int x, int y)
1052+
{
1053+
hudOffsetX.setValue(x);
1054+
hudOffsetY.setValue(y);
1055+
}
1056+
10071057
public boolean isShowRegistryName()
10081058
{
10091059
return showRegistryName.isChecked();
@@ -1039,6 +1089,8 @@ public String sourceLabel()
10391089
return "held by " + (sourceName != null ? sourceName : "mob");
10401090
if(sourceType == SourceType.MOB_WORN)
10411091
return "worn by " + (sourceName != null ? sourceName : "mob");
1092+
if(sourceType == SourceType.ITEM_FRAME)
1093+
return "in item frame";
10421094
return "";
10431095
}
10441096

@@ -1151,6 +1203,7 @@ public enum SourceType
11511203
{
11521204
GROUND,
11531205
XP_ORB,
1206+
ITEM_FRAME,
11541207
MOB_HELD,
11551208
MOB_WORN
11561209
}

src/main/java/net/wurstclient/hacks/itemhandler/ItemHandlerHud.java

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@
2222
import net.minecraft.client.Minecraft;
2323
import net.minecraft.client.gui.GuiGraphics;
2424
import net.minecraft.client.gui.Font;
25+
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
2526
import net.wurstclient.WurstClient;
2627
import net.wurstclient.util.RenderUtils;
2728

2829
public class ItemHandlerHud
2930
{
3031
private static final Minecraft MC = WurstClient.MC;
31-
// rendering per-frame guard removed: was causing flicker
32+
private boolean dragging;
33+
private double dragStartMouseX;
34+
private double dragStartMouseY;
35+
private int dragStartOffsetX;
36+
private int dragStartOffsetY;
37+
private int dragOffsetX;
38+
private int dragOffsetY;
3239
private boolean lastLeftDown = false;
3340

3441
public void render(GuiGraphics context, float partialTicks)
@@ -113,8 +120,6 @@ class MergeEntry
113120
}
114121

115122
int guiW = context.guiWidth();
116-
int x = guiW + hack.getHudOffsetX();
117-
int y = hack.getHudOffsetY();
118123

119124
// Render only one popup (expanded list). The previous header
120125
// duplicate is removed to avoid showing two linked popups.
@@ -148,11 +153,26 @@ class MergeEntry
148153
iconSpace + padding + maxNameW + gap + maxDistW + padding;
149154
if(boxWidth < 120)
150155
boxWidth = 120;
156+
157+
int hudOffsetX = dragging ? dragOffsetX : hack.getHudOffsetX();
158+
int hudOffsetY = dragging ? dragOffsetY : hack.getHudOffsetY();
159+
int x = guiW + hudOffsetX;
160+
int y = hudOffsetY;
151161
int ex = x - boxWidth;
152162
int ey = y + headerHeight;
153163
int rowHeight = 16;
154164
int footer = items.size() > maxDisplay ? 1 : 0;
155165
int height = maxDisplay * rowHeight + footer * rowHeight + 6;
166+
167+
handleDrag(context, hack, ex, ey, boxWidth, height);
168+
169+
hudOffsetX = dragging ? dragOffsetX : hack.getHudOffsetX();
170+
hudOffsetY = dragging ? dragOffsetY : hack.getHudOffsetY();
171+
x = guiW + hudOffsetX;
172+
y = hudOffsetY;
173+
ex = x - boxWidth;
174+
ey = y + headerHeight;
175+
156176
context.fill(ex, ey, ex + boxWidth, ey + height, 0xCC101010);
157177
context.guiRenderState.up();
158178

@@ -219,22 +239,79 @@ class MergeEntry
219239
scale * 0.95);
220240
}
221241

242+
// Do not open the ItemHandler GUI from the popup via mouse clicks.
243+
// Opening the ItemHandler GUI remains available via keybind/command
244+
// and the settings button.
245+
}
246+
247+
private void handleDrag(GuiGraphics context, ItemHandlerHack hack, int ex,
248+
int ey, int boxWidth, int height)
249+
{
250+
Window window = MC.getWindow();
251+
if(window == null)
252+
{
253+
dragging = false;
254+
lastLeftDown = false;
255+
return;
256+
}
257+
258+
boolean leftDown = GLFW.glfwGetMouseButton(window.handle(),
259+
GLFW.GLFW_MOUSE_BUTTON_LEFT) == GLFW.GLFW_PRESS;
260+
boolean containerOpen = MC.screen instanceof AbstractContainerScreen<?>;
261+
if(!containerOpen)
262+
{
263+
if(dragging)
264+
{
265+
hack.setHudOffsets(dragOffsetX, dragOffsetY);
266+
dragging = false;
267+
}
268+
lastLeftDown = leftDown;
269+
return;
270+
}
271+
222272
double mouseX = getScaledMouseX(context);
223273
double mouseY = getScaledMouseY(context);
224-
// hitbox covers the single list popup
225274
boolean overList = mouseX >= ex && mouseX <= ex + boxWidth
226275
&& mouseY >= ey && mouseY <= ey + height;
227-
Window window = MC.getWindow();
228-
boolean leftDown = GLFW.glfwGetMouseButton(window.handle(),
229-
GLFW.GLFW_MOUSE_BUTTON_LEFT) == GLFW.GLFW_PRESS;
230-
// Do not open the ItemHandler GUI from the popup via mouse clicks.
231-
// This avoids the popup behind other full-screen GUIs triggering
232-
// the ItemHandler screen when clicking in overlapping areas.
233-
// (Opening the ItemHandler GUI is available via the dedicated
234-
// settings button or a keybind/command.)
276+
277+
if(!dragging && leftDown && !lastLeftDown && overList)
278+
{
279+
dragging = true;
280+
dragStartMouseX = mouseX;
281+
dragStartMouseY = mouseY;
282+
dragStartOffsetX = hack.getHudOffsetX();
283+
dragStartOffsetY = hack.getHudOffsetY();
284+
dragOffsetX = dragStartOffsetX;
285+
dragOffsetY = dragStartOffsetY;
286+
}
287+
288+
if(dragging)
289+
{
290+
if(leftDown)
291+
{
292+
int dx = (int)Math.round(mouseX - dragStartMouseX);
293+
int dy = (int)Math.round(mouseY - dragStartMouseY);
294+
int minX = hack.getHudOffsetMinX();
295+
int maxX = hack.getHudOffsetMaxX();
296+
int minY = hack.getHudOffsetMinY();
297+
int maxY = hack.getHudOffsetMaxY();
298+
dragOffsetX = clamp(dragStartOffsetX + dx, minX, maxX);
299+
dragOffsetY = clamp(dragStartOffsetY + dy, minY, maxY);
300+
}else
301+
{
302+
hack.setHudOffsets(dragOffsetX, dragOffsetY);
303+
dragging = false;
304+
}
305+
}
306+
235307
lastLeftDown = leftDown;
236308
}
237309

310+
private static int clamp(int value, int min, int max)
311+
{
312+
return Math.max(min, Math.min(max, value));
313+
}
314+
238315
private static double getScaledMouseX(GuiGraphics context)
239316
{
240317
Window window = MC.getWindow();

0 commit comments

Comments
 (0)