Skip to content

Commit 8641149

Browse files
committed
Updated ItemHandler and WindChargeKey
1 parent f21c6ea commit 8641149

5 files changed

Lines changed: 159 additions & 64 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ Reports number of waypoints changed.
409409
- Can also filter out default mob items to prevent spam
410410
- Optionally can read the contents of signs in the popup HUD
411411
- Optionally pin special items (from ItemESP list) to the top of the popup HUD
412+
- Optionally display enchantments of gear in lieu of the registry name
412413

413414
![Popup](https://i.imgur.com/VQw20x0.png)
414415
![GUI](https://i.imgur.com/oZFLufE.png)

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

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
package net.wurstclient.hacks;
99

1010
import com.mojang.blaze3d.platform.InputConstants;
11+
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
12+
import org.lwjgl.glfw.GLFW;
13+
import net.minecraft.client.KeyMapping;
1114
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
1215
import net.minecraft.world.InteractionHand;
1316
import net.minecraft.world.InteractionResult;
@@ -20,17 +23,14 @@
2023
import net.wurstclient.settings.CheckboxSetting;
2124
import net.wurstclient.settings.SliderSetting;
2225
import net.wurstclient.settings.SliderSetting.ValueDisplay;
23-
import net.wurstclient.settings.TextFieldSetting;
2426

2527
@SearchTags({"wind charge", "auto wind charge", "windcharge"})
2628
public final class WindChargeKeyHack extends Hack implements UpdateListener
2729
{
28-
private final TextFieldSetting keybind = new TextFieldSetting("Keybind",
29-
"Determines the activation key.\n\n"
30-
+ "Use translation keys such as \u00a7lkey.keyboard.g\u00a7r.\n"
31-
+ "You can find these by looking at the F3 debug screen or by\n"
32-
+ "checking vanilla keybind configuration files.",
33-
"key.keyboard.g", this::isValidKey);
30+
private static final KeyMapping activationKey =
31+
KeyBindingHelper.registerKeyBinding(new KeyMapping(
32+
"key.wurst.windchargekey", InputConstants.Type.KEYSYM,
33+
GLFW.GLFW_KEY_SPACE, KeyMapping.Category.MISC));
3434

3535
private final SliderSetting switchDelayMs = new SliderSetting(
3636
"Switch delay", 50, 0, 500, 5, ValueDisplay.INTEGER.withSuffix("ms"));
@@ -53,7 +53,6 @@ public final class WindChargeKeyHack extends Hack implements UpdateListener
5353
private final SliderSetting jumpDelayMs = new SliderSetting("Jump delay",
5454
10, 0, 200, 5, ValueDisplay.INTEGER.withSuffix("ms"));
5555

56-
private boolean keyPressed;
5756
private int originalSlot = -1;
5857
private boolean needsSlotRestore;
5958
private boolean firstThrow = true;
@@ -75,7 +74,6 @@ public WindChargeKeyHack()
7574
super("WindChargeKey");
7675
setCategory(Category.COMBAT);
7776

78-
addSetting(keybind);
7977
addSetting(switchDelayMs);
8078
addSetting(throwDelayMs);
8179
addSetting(silentMode);
@@ -109,19 +107,9 @@ public void onUpdate()
109107
return;
110108

111109
if(MC.screen != null)
112-
{
113-
keyPressed = false;
114110
return;
115-
}
116-
117-
InputConstants.Key key = getBoundKey();
118-
if(key == null)
119-
return;
120-
121-
boolean currentlyPressed =
122-
InputConstants.isKeyDown(MC.getWindow(), key.getValue());
123111

124-
if(currentlyPressed && !keyPressed)
112+
while(activationKey.consumeClick())
125113
handleWindChargeThrow();
126114

127115
long now = System.currentTimeMillis();
@@ -166,7 +154,6 @@ public void onUpdate()
166154
originalSlot = -1;
167155
}
168156

169-
keyPressed = currentlyPressed;
170157
}
171158

172159
private void handleWindChargeThrow()
@@ -360,18 +347,6 @@ private int findWindChargeInHotbar()
360347
return -1;
361348
}
362349

363-
private InputConstants.Key getBoundKey()
364-
{
365-
try
366-
{
367-
return InputConstants.getKey(keybind.getValue());
368-
369-
}catch(IllegalArgumentException e)
370-
{
371-
return null;
372-
}
373-
}
374-
375350
private long getSwitchDelay()
376351
{
377352
return Math.max(0L, Math.round(switchDelayMs.getValue()));
@@ -387,26 +362,13 @@ private long getJumpDelay()
387362
return Math.max(0L, Math.round(jumpDelayMs.getValue()));
388363
}
389364

390-
private boolean isValidKey(String translationKey)
391-
{
392-
try
393-
{
394-
return InputConstants.getKey(translationKey) != null;
395-
396-
}catch(IllegalArgumentException e)
397-
{
398-
return false;
399-
}
400-
}
401-
402365
private void resetState()
403366
{
404367
clearPending();
405368

406369
if(restorePitch && MC.player != null)
407370
restorePitchImmediate(savedPitch);
408371

409-
keyPressed = false;
410372
originalSlot = -1;
411373
needsSlotRestore = false;
412374
firstThrow = true;

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

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
import java.util.Locale;
2222
import java.util.Set;
2323
import java.util.UUID;
24+
import java.util.LinkedHashSet;
2425
import net.minecraft.client.gui.screens.Screen;
2526
import net.minecraft.client.player.LocalPlayer;
2627
import net.minecraft.core.BlockPos;
28+
import net.minecraft.core.Holder;
29+
import net.minecraft.core.component.DataComponents;
2730
import net.minecraft.world.entity.Entity;
2831
import net.minecraft.world.entity.item.ItemEntity;
2932
import net.minecraft.world.entity.ExperienceOrb;
@@ -36,6 +39,8 @@
3639
import net.minecraft.world.InteractionHand;
3740
import net.minecraft.world.item.ItemStack;
3841
import net.minecraft.world.item.Items;
42+
import net.minecraft.world.item.enchantment.Enchantment;
43+
import net.minecraft.world.item.enchantment.ItemEnchantments;
3944
import net.minecraft.world.level.block.entity.SignBlockEntity;
4045
import net.minecraft.world.level.block.entity.SignText;
4146
import net.minecraft.world.phys.Vec3;
@@ -55,6 +60,7 @@
5560
import com.google.gson.JsonElement;
5661
import com.google.gson.JsonNull;
5762
import com.google.gson.JsonObject;
63+
import it.unimi.dsi.fastutil.objects.Object2IntMap;
5864
// no screen import needed; we embed ItemESP's editor component directly
5965
import net.wurstclient.util.InventoryUtils;
6066
import net.wurstclient.util.chunk.ChunkUtils;
@@ -118,6 +124,11 @@ public class ItemHandlerHack extends Hack
118124
private final CheckboxSetting showRegistryName =
119125
new CheckboxSetting("Show registry names", false);
120126

127+
private final CheckboxSetting showEnchantmentsInNames =
128+
new CheckboxSetting("Show enchantments in names",
129+
"Shows enchantments on the second line in ItemHandler HUD and GUI.",
130+
false);
131+
121132
// How many items to show in the popup HUD
122133
private final SliderSetting popupMaxItems = new SliderSetting(
123134
"Popup HUD max items", 8, 1, 10, 1, ValueDisplay.INTEGER);
@@ -182,6 +193,7 @@ public ItemHandlerHack()
182193
addSetting(new ButtonSetting("Open ItemHandler GUI", this::openScreen));
183194
addSetting(hudEnabled);
184195
addSetting(showRegistryName);
196+
addSetting(showEnchantmentsInNames);
185197
addSetting(includeMobEquipment);
186198
addSetting(filterDefaultMobEquipment);
187199
addSetting(respectItemEspIgnores);
@@ -561,7 +573,8 @@ private void scanNearbyItems()
561573

562574
private void scanNearbySigns()
563575
{
564-
if(!showSignsInHud.isChecked())
576+
boolean guiOpen = MC.screen instanceof ItemHandlerScreen;
577+
if(!showSignsInHud.isChecked() && !guiOpen)
565578
{
566579
trackedSigns.clear();
567580
return;
@@ -985,14 +998,26 @@ public List<NearbySign> getTrackedSigns()
985998
return List.copyOf(trackedSigns);
986999
}
9871000

1001+
public static String getSignTraceId(BlockPos pos)
1002+
{
1003+
if(pos == null)
1004+
return null;
1005+
return "sign:" + pos.asLong();
1006+
}
1007+
9881008
public boolean isShowSignsInHud()
9891009
{
9901010
return showSignsInHud.isChecked();
9911011
}
9921012

9931013
public record NearbySign(BlockPos pos, ItemStack icon, String text,
9941014
double distance)
995-
{}
1015+
{
1016+
public String traceId()
1017+
{
1018+
return getSignTraceId(pos);
1019+
}
1020+
}
9961021

9971022
public boolean isHudEnabled()
9981023
{
@@ -1063,6 +1088,11 @@ public boolean isShowRegistryName()
10631088
return showRegistryName.isChecked();
10641089
}
10651090

1091+
public boolean isShowEnchantmentsInNames()
1092+
{
1093+
return showEnchantmentsInNames.isChecked();
1094+
}
1095+
10661096
public record GroundItem(int entityId, UUID uuid, ItemStack stack,
10671097
double distance, Vec3 position, SourceType sourceType,
10681098
String sourceName)
@@ -1084,6 +1114,8 @@ public String traceId()
10841114
int xp = net.wurstclient.util.ItemUtils.getXpAmount(stack);
10851115
return baseId + ":xp:" + xp;
10861116
}
1117+
if(sourceType == SourceType.ITEM_FRAME)
1118+
return baseId + ":item_frame";
10871119
return baseId;
10881120
}
10891121

@@ -1104,6 +1136,7 @@ public String displayName()
11041136
if(name == null || name.isBlank())
11051137
name = net.minecraft.core.registries.BuiltInRegistries.ITEM
11061138
.getKey(stack.getItem()).getPath();
1139+
11071140
String label = sourceLabel();
11081141
if(label == null || label.isBlank())
11091142
return name;
@@ -1163,6 +1196,22 @@ public void onRender(PoseStack matrixStack, float partialTicks)
11631196
if(shouldDrawTracers)
11641197
ends.add(new RenderUtils.ColoredPoint(p, 0));
11651198
}
1199+
1200+
for(NearbySign sign : trackedSigns)
1201+
{
1202+
if(sign == null || sign.pos() == null)
1203+
continue;
1204+
String traceId = sign.traceId();
1205+
boolean traced = traceId != null && isTraced(traceId);
1206+
if(!traced)
1207+
continue;
1208+
BlockPos pos = sign.pos();
1209+
Vec3 p = Vec3.atCenterOf(pos);
1210+
if(shouldDrawBoxes)
1211+
boxes.add(new AABB(pos));
1212+
if(shouldDrawTracers)
1213+
ends.add(new RenderUtils.ColoredPoint(p, 0));
1214+
}
11661215
boolean hasBoxes = shouldDrawBoxes && boxes != null && !boxes.isEmpty();
11671216
boolean hasTracers =
11681217
shouldDrawTracers && ends != null && !ends.isEmpty();
@@ -1263,4 +1312,35 @@ public java.util.Set<net.wurstclient.keybinds.PossibleKeybind> getPossibleKeybin
12631312
return java.util.Collections.emptySet();
12641313
}
12651314
};
1315+
1316+
public String getEnchantmentSummary(ItemStack stack)
1317+
{
1318+
if(stack == null || stack.isEmpty())
1319+
return "";
1320+
1321+
ArrayList<String> parts = new ArrayList<>();
1322+
LinkedHashSet<String> seen = new LinkedHashSet<>();
1323+
appendEnchantmentParts(parts, seen, stack
1324+
.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY));
1325+
appendEnchantmentParts(parts, seen, stack.getOrDefault(
1326+
DataComponents.STORED_ENCHANTMENTS, ItemEnchantments.EMPTY));
1327+
if(parts.isEmpty())
1328+
return "";
1329+
return String.join(", ", parts);
1330+
}
1331+
1332+
private static void appendEnchantmentParts(List<String> out,
1333+
Set<String> seen, ItemEnchantments enchantments)
1334+
{
1335+
for(Object2IntMap.Entry<Holder<Enchantment>> entry : enchantments
1336+
.entrySet())
1337+
{
1338+
Holder<Enchantment> holder = entry.getKey();
1339+
int level = entry.getIntValue();
1340+
String key = holder.getRegisteredName() + "#" + level;
1341+
if(!seen.add(key))
1342+
continue;
1343+
out.add(Enchantment.getFullname(holder, level).getString());
1344+
}
1345+
}
12661346
}

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ class MergeEntry
143143
MergeEntry me = items.get(ii);
144144
String name = me.displayName;
145145
int wName = (int)Math.round(font.width(name) * scale);
146+
String subtitle = "";
147+
if(hack != null)
148+
{
149+
if(hack.isShowEnchantmentsInNames())
150+
subtitle = hack.getEnchantmentSummary(me.rep);
151+
if(subtitle.isBlank() && hack.isShowRegistryName())
152+
subtitle =
153+
net.minecraft.core.registries.BuiltInRegistries.ITEM
154+
.getKey(me.rep.getItem()).toString();
155+
}
156+
if(!subtitle.isBlank())
157+
wName = Math.max(wName,
158+
(int)Math.round(font.width(subtitle) * (scale * 0.6)));
146159
String dist = ((int)Math.round(me.closest)) + " blocks";
147160
int wDist = (int)Math.round(font.width(dist) * scale);
148161
maxNameW = Math.max(maxNameW, wName);
@@ -217,14 +230,19 @@ class MergeEntry
217230
0xFFFFFFFF, false, countScale);
218231
}
219232

220-
// optionally show registry id as subtitle
221-
if(hack != null && hack.isShowRegistryName())
233+
// Optional subtitle line: enchantments or registry id.
234+
if(hack != null)
222235
{
223-
String reg =
224-
net.minecraft.core.registries.BuiltInRegistries.ITEM
225-
.getKey(me.rep.getItem()).toString();
226-
RenderUtils.drawScaledText(context, tr, reg, ex + 22, iy + 9,
227-
0xFF909090, false, 0.6);
236+
String subtitle = "";
237+
if(hack.isShowEnchantmentsInNames())
238+
subtitle = hack.getEnchantmentSummary(me.rep);
239+
if(subtitle.isBlank() && hack.isShowRegistryName())
240+
subtitle =
241+
net.minecraft.core.registries.BuiltInRegistries.ITEM
242+
.getKey(me.rep.getItem()).toString();
243+
if(!subtitle.isBlank())
244+
RenderUtils.drawScaledText(context, tr, subtitle, ex + 22,
245+
iy + 9, 0xFF909090, false, 0.6);
228246
}
229247
i++;
230248
}

0 commit comments

Comments
 (0)