Skip to content

Commit f69067f

Browse files
committed
Fix EnchantmentHandler
1 parent 1722817 commit f69067f

2 files changed

Lines changed: 72 additions & 6 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public final class AntiVoidHack extends Hack implements UpdateListener
4242
"Treat the Overworld, Nether and End as if they had a solid floor below you.",
4343
false);
4444

45-
private final SliderSetting overworldFalseFloorY = new SliderSetting(
46-
"Overworld floor Y",
47-
"Block Y for the fake Overworld floor. The walkable surface is one block above this.",
48-
-68, -100, -64, 1, ValueDisplay.INTEGER);
45+
private final SliderSetting overworldFalseFloorY = new SliderSetting(
46+
"Overworld floor Y",
47+
"Block Y for the fake Overworld floor. The walkable surface is one block above this.",
48+
-68, -100, -64, 1, ValueDisplay.INTEGER);
4949

5050
private final SliderSetting netherFalseFloorY = new SliderSetting(
5151
"Nether floor Y",

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import net.minecraft.world.inventory.AbstractContainerMenu;
3434
import net.minecraft.world.inventory.ChestMenu;
3535
import net.minecraft.world.inventory.ContainerInput;
36+
import net.minecraft.world.inventory.CraftingMenu;
37+
import net.minecraft.world.inventory.ResultSlot;
3638
import net.minecraft.world.inventory.Slot;
3739
import net.minecraft.world.item.Item;
3840
import net.minecraft.world.item.ItemStack;
@@ -282,6 +284,11 @@ public void renderOnHandledScreen(AbstractContainerScreen<?> screen,
282284

283285
if(MC.player == null || MC.gameMode == null)
284286
return;
287+
if(isExcludedScreen(screen))
288+
{
289+
clearRenderState();
290+
return;
291+
}
285292
if(screen instanceof InventoryScreen
286293
&& !showOnInventoryScreen.isChecked())
287294
return;
@@ -368,6 +375,10 @@ public boolean handleMouseClick(AbstractContainerScreen<?> screen,
368375
{
369376
if(!lastRenderActive)
370377
return false;
378+
if(isExcludedScreen(screen))
379+
return false;
380+
if(isOverHandledSlot(screen, mouseX, mouseY))
381+
return false;
371382

372383
// Handle scroll bar click/drag
373384
if(button == 0 && isInsideScrollBar(mouseX, mouseY))
@@ -457,6 +468,34 @@ else if(hitbox.entry instanceof PotionEntry potion)
457468
return isInsidePanel(mouseX, mouseY);
458469
}
459470

471+
private boolean isOverHandledSlot(AbstractContainerScreen<?> screen,
472+
double mouseX, double mouseY)
473+
{
474+
if(screen == null)
475+
return false;
476+
477+
HandledScreenAccessor accessor = (HandledScreenAccessor)screen;
478+
AbstractContainerMenu handler = screen.getMenu();
479+
if(handler == null || handler.slots == null)
480+
return false;
481+
482+
int left = accessor.getX();
483+
int top = accessor.getY();
484+
for(Slot slot : handler.slots)
485+
{
486+
if(slot == null)
487+
continue;
488+
489+
int slotX = left + slot.x;
490+
int slotY = top + slot.y;
491+
if(mouseX >= slotX && mouseX < slotX + 16 && mouseY >= slotY
492+
&& mouseY < slotY + 16)
493+
return true;
494+
}
495+
496+
return false;
497+
}
498+
460499
public boolean handleMouseRelease(AbstractContainerScreen<?> screen,
461500
double mouseX, double mouseY, int button)
462501
{
@@ -481,6 +520,8 @@ public boolean handleMouseScroll(AbstractContainerScreen<?> screen,
481520
{
482521
if(!lastRenderActive)
483522
return false;
523+
if(isExcludedScreen(screen))
524+
return false;
484525

485526
if(!isInsidePanel(mouseX, mouseY))
486527
return false;
@@ -527,6 +568,23 @@ private boolean isInsideScrollBar(double mouseX, double mouseY)
527568
&& mouseY <= panelY + panelHeight;
528569
}
529570

571+
private boolean isExcludedScreen(AbstractContainerScreen<?> screen)
572+
{
573+
return screen != null && screen.getMenu() instanceof CraftingMenu;
574+
}
575+
576+
private void clearRenderState()
577+
{
578+
lastRenderActive = false;
579+
hitboxes.clear();
580+
hoveredSlotId = -1;
581+
hoverStartMs = 0L;
582+
scrollBarDragging = false;
583+
panelDragging = false;
584+
if(SlotHighlighter.INSTANCE.isEnchantmentHandlerActive())
585+
SlotHighlighter.INSTANCE.clearEnchantmentHandlerActive();
586+
}
587+
530588
private double getScrollThumbHeight(double trackHeight)
531589
{
532590
if(contentHeight <= 0 || trackHeight <= 0)
@@ -1106,7 +1164,7 @@ private void refreshEntries(AbstractContainerMenu handler)
11061164
for(int i = 0; i < containerSlots; i++)
11071165
{
11081166
Slot slot = slots.get(i);
1109-
if(slot == null || !slot.hasItem())
1167+
if(shouldSkipScannedSlot(slot))
11101168
continue;
11111169

11121170
ItemStack stack = slot.getItem();
@@ -1244,7 +1302,7 @@ private void refreshEntries(AbstractContainerMenu handler)
12441302
for(int i = containerSlots; i < scanSlots; i++)
12451303
{
12461304
Slot slot = slots.get(i);
1247-
if(slot == null || !slot.hasItem())
1305+
if(shouldSkipScannedSlot(slot))
12481306
continue;
12491307
ItemStack stack = slot.getItem();
12501308
if(stack.isEmpty())
@@ -1435,6 +1493,14 @@ private void refreshEntries(AbstractContainerMenu handler)
14351493
}));
14361494
}
14371495

1496+
private boolean shouldSkipScannedSlot(Slot slot)
1497+
{
1498+
if(slot == null || !slot.hasItem())
1499+
return true;
1500+
1501+
return slot instanceof ResultSlot;
1502+
}
1503+
14381504
private GearEntry buildGearEntry(Slot slot, ItemStack stack,
14391505
GearCategory category,
14401506
Set<Object2IntMap.Entry<Holder<Enchantment>>> enchantments)

0 commit comments

Comments
 (0)