Skip to content

Commit e780aa2

Browse files
committed
Navigator and EnchantmentHandler Fixes
1 parent cafee11 commit e780aa2

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

src/main/java/net/wurstclient/clickgui/ClickGui.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,22 @@ public boolean handleNavigatorPopupClick(double mouseX, double mouseY,
322322
return popupClicked;
323323
}
324324

325+
public boolean handleNavigatorMouseScroll(double mouseX, double mouseY,
326+
double delta)
327+
{
328+
boolean popupScrolled = handlePopupMouseScroll(mouseX, mouseY, delta);
329+
if(popupScrolled)
330+
{
331+
for(Popup popup : popups)
332+
if(popup.getOwner().getParent().isClosing())
333+
popup.close();
334+
335+
popups.removeIf(Popup::isClosing);
336+
}
337+
338+
return popupScrolled;
339+
}
340+
325341
public void handleNavigatorMouseClick(double cMouseX, double cMouseY,
326342
int mouseButton, Window window, Click context)
327343
{

src/main/java/net/wurstclient/clickgui/Window.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class Window
2020
private int y;
2121
private int width;
2222
private int height;
23+
private boolean clampPosition = true;
2324

2425
private boolean valid;
2526
private final ArrayList<Component> children = new ArrayList<>();
@@ -68,6 +69,9 @@ public final void setTitle(String title)
6869
*/
6970
public final int getX()
7071
{
72+
if(!clampPosition)
73+
return x;
74+
7175
int scaledWidth = WurstClient.MC.getWindow().getScaledWidth();
7276
return MathHelper.clamp(x, -width + 1, scaledWidth - 1);
7377
}
@@ -92,6 +96,9 @@ public final void setX(int x)
9296
*/
9397
public final int getY()
9498
{
99+
if(!clampPosition)
100+
return y;
101+
95102
int scaledHeight = WurstClient.MC.getWindow().getScaledHeight();
96103
return MathHelper.clamp(y, -12, scaledHeight - 1);
97104
}
@@ -111,6 +118,11 @@ public final void setY(int y)
111118
this.y = y;
112119
}
113120

121+
public final void setClampPosition(boolean clampPosition)
122+
{
123+
this.clampPosition = clampPosition;
124+
}
125+
114126
public final int getWidth()
115127
{
116128
return width;

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ private void takeEntry(GearEntry entry, ScreenHandler handler)
13911391
if(entry.slotId < 0)
13921392
return;
13931393

1394-
Slot slot = handler.getSlot(entry.slotId);
1394+
Slot slot = getSlotSafe(handler, entry.slotId);
13951395
if(slot == null || !slot.hasStack())
13961396
return;
13971397

@@ -1408,7 +1408,7 @@ private void takeEntry(BookEntry entry, ScreenHandler handler)
14081408
if(entry.slotId < 0)
14091409
return;
14101410

1411-
Slot slot = handler.getSlot(entry.slotId);
1411+
Slot slot = getSlotSafe(handler, entry.slotId);
14121412
if(slot == null || !slot.hasStack())
14131413
return;
14141414

@@ -1425,7 +1425,7 @@ private void takeEntry(PotionEntry entry, ScreenHandler handler)
14251425
if(entry.slotId < 0)
14261426
return;
14271427

1428-
Slot slot = handler.getSlot(entry.slotId);
1428+
Slot slot = getSlotSafe(handler, entry.slotId);
14291429
if(slot == null || !slot.hasStack())
14301430
return;
14311431

@@ -1460,7 +1460,7 @@ private void takeGearCategory(GearCategory category, ScreenHandler handler,
14601460
{
14611461
if(entry.slotId < 0)
14621462
continue; // display-only (in shulker)
1463-
Slot slot = handler.getSlot(entry.slotId);
1463+
Slot slot = getSlotSafe(handler, entry.slotId);
14641464
if(slot == null || !slot.hasStack())
14651465
continue;
14661466

@@ -1497,7 +1497,7 @@ private void takeBookCategory(BookCategory category, ScreenHandler handler,
14971497
{
14981498
if(entry.slotId < 0)
14991499
continue;
1500-
Slot slot = handler.getSlot(entry.slotId);
1500+
Slot slot = getSlotSafe(handler, entry.slotId);
15011501
if(slot == null || !slot.hasStack())
15021502
continue;
15031503
MC.interactionManager.clickSlot(handler.syncId, entry.slotId, 0,
@@ -1533,7 +1533,7 @@ private void takePotionCategory(PotionCategory category,
15331533
{
15341534
if(entry.slotId < 0)
15351535
continue;
1536-
Slot slot = handler.getSlot(entry.slotId);
1536+
Slot slot = getSlotSafe(handler, entry.slotId);
15371537
if(slot == null || !slot.hasStack())
15381538
continue;
15391539
MC.interactionManager.clickSlot(handler.syncId, entry.slotId, 0,
@@ -1543,6 +1543,18 @@ private void takePotionCategory(PotionCategory category,
15431543
needsRescan = true;
15441544
}
15451545

1546+
private Slot getSlotSafe(ScreenHandler handler, int slotId)
1547+
{
1548+
if(handler == null || slotId < 0)
1549+
return null;
1550+
1551+
List<Slot> slots = handler.slots;
1552+
if(slots == null || slotId >= slots.size())
1553+
return null;
1554+
1555+
return handler.getSlot(slotId);
1556+
}
1557+
15461558
private int panelInnerHeight()
15471559
{
15481560
float scale = MathHelper.clamp(textScale.getValueF(), 0.5F, 1.25F);

src/main/java/net/wurstclient/navigator/NavigatorFeatureScreen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public NavigatorFeatureScreen(Feature feature, NavigatorMainScreen parent)
6363
this.parent = parent;
6464
hasBackground = false;
6565

66+
window.setClampPosition(false);
67+
6668
for(Setting setting : feature.getSettings().values())
6769
{
6870
Component c = setting.getComponent();

src/main/java/net/wurstclient/navigator/NavigatorScreen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public final boolean mouseReleased(Click context)
110110
public final boolean mouseScrolled(double mouseX, double mouseY,
111111
double horizontalAmount, double verticalAmount)
112112
{
113+
if(WurstClient.INSTANCE.getGui().handleNavigatorMouseScroll(mouseX,
114+
mouseY, verticalAmount))
115+
return true;
116+
113117
// scrollbar
114118
if(!scrollbarLocked)
115119
{

0 commit comments

Comments
 (0)