Skip to content

Commit ba8c2e2

Browse files
committed
Added Server Search & Command Auto-Complete. Update LootSearch,
ChestSearch, CoordLogger
1 parent a336268 commit ba8c2e2

9 files changed

Lines changed: 514 additions & 52 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fabric_api_version=0.147.0+26.1.2
1515

1616
# Mod Properties
1717
mod_version=v7.53.1-CevAPI-MC26.1.2
18-
fork_release_version=0.54
18+
fork_release_version=0.55
1919
maven_group=net.wurstclient
2020
archives_base_name=Wurst-Client
2121
mod_loader=Fabric

src/main/java/net/wurstclient/chestsearch/ChestDatabase.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.List;
2222
import java.util.Locale;
2323
import java.util.stream.Collectors;
24+
import net.wurstclient.WurstClient;
25+
import net.wurstclient.hacks.ChestSearchHack;
2426

2527
public class ChestDatabase
2628
{
@@ -77,8 +79,8 @@ public synchronized void save()
7779
try(FileWriter w = new FileWriter(file))
7880
{
7981
gson.toJson(entries, w);
80-
System.out.println("[ChestDatabase] saved " + entries.size()
81-
+ " entries to " + file.getAbsolutePath());
82+
log("[ChestDatabase] saved " + entries.size() + " entries to "
83+
+ file.getAbsolutePath());
8284
}catch(Exception e)
8385
{
8486
e.printStackTrace();
@@ -126,9 +128,8 @@ public synchronized void upsert(ChestEntry entry)
126128
entry.touch();
127129
entries.add(entry);
128130
finalizeInsert(entry);
129-
System.out.println(
130-
"[ChestDatabase] merged entry by contents; preserved primary="
131-
+ entry.x + "," + entry.y + "," + entry.z);
131+
log("[ChestDatabase] merged entry by contents; preserved primary="
132+
+ entry.x + "," + entry.y + "," + entry.z);
132133
return;
133134
}
134135
}
@@ -152,7 +153,7 @@ public synchronized void upsert(ChestEntry entry)
152153
it.remove();
153154
entries.add(entry);
154155
finalizeInsert(entry);
155-
System.out.println("[ChestDatabase] updated entry at bounds "
156+
log("[ChestDatabase] updated entry at bounds "
156157
+ entry.getMinPos() + " -> " + entry.getMaxPos()
157158
+ " facing=" + entry.facing + " (preserved primary="
158159
+ entry.x + "," + entry.y + "," + entry.z + ")");
@@ -162,9 +163,8 @@ public synchronized void upsert(ChestEntry entry)
162163
entry.touch();
163164
entries.add(entry);
164165
finalizeInsert(entry);
165-
System.out.println(
166-
"[ChestDatabase] added entry at bounds " + entry.getMinPos()
167-
+ " -> " + entry.getMaxPos() + " facing=" + entry.facing);
166+
log("[ChestDatabase] added entry at bounds " + entry.getMinPos()
167+
+ " -> " + entry.getMaxPos() + " facing=" + entry.facing);
168168
}
169169

170170
public synchronized void removeAt(String serverIp, String dimension, int x,
@@ -175,8 +175,7 @@ public synchronized void removeAt(String serverIp, String dimension, int x,
175175
&& e.x == x && e.y == y && e.z == z))
176176
.collect(Collectors.toList());
177177
save();
178-
System.out.println(
179-
"[ChestDatabase] removed entry at " + x + "," + y + "," + z);
178+
log("[ChestDatabase] removed entry at " + x + "," + y + "," + z);
180179
}
181180

182181
public synchronized List<ChestEntry> search(String query)
@@ -320,8 +319,7 @@ private void finalizeInsert(ChestEntry entry)
320319
{
321320
boolean removed = removeOverlappingDuplicates(entry);
322321
if(removed)
323-
System.out.println(
324-
"[ChestDatabase] cleaned overlapping duplicates after insert.");
322+
log("[ChestDatabase] cleaned overlapping duplicates after insert.");
325323
save();
326324
}
327325

@@ -360,14 +358,35 @@ private boolean removeOverlappingDuplicates(ChestEntry reference)
360358
if(!overlap)
361359
continue;
362360
it.remove();
363-
System.out
364-
.println("[ChestDatabase] removed overlapping duplicate at "
365-
+ other.getMinPos() + " -> " + other.getMaxPos());
361+
log("[ChestDatabase] removed overlapping duplicate at "
362+
+ other.getMinPos() + " -> " + other.getMaxPos());
366363
removed = true;
367364
}
368365
return removed;
369366
}
370367

368+
private static void log(String message)
369+
{
370+
if(shouldLogConsole())
371+
System.out.println(message);
372+
}
373+
374+
private static boolean shouldLogConsole()
375+
{
376+
try
377+
{
378+
if(WurstClient.INSTANCE == null
379+
|| WurstClient.INSTANCE.getHax() == null)
380+
return true;
381+
ChestSearchHack hack =
382+
WurstClient.INSTANCE.getHax().chestSearchHack;
383+
return hack == null || hack.shouldShowConsoleLogs();
384+
}catch(Throwable ignored)
385+
{
386+
return true;
387+
}
388+
}
389+
371390
private boolean dedupeLoadedEntries()
372391
{
373392
if(entries == null || entries.isEmpty())

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public final class ChestSearchHack extends Hack
6969
new CheckboxSetting("Loot mismatch notifications",
7070
"Show a chat notification when a chest does not match the loot table.",
7171
false);
72+
private final CheckboxSetting consoleLogs =
73+
new CheckboxSetting("Console logs",
74+
"Print ChestSearch debug messages to the console.", true);
7275
private final SliderSetting textScale = new SliderSetting("Text scale", 1.0,
7376
0.5, 1.25, 0.05, ValueDisplay.DECIMAL);
7477

@@ -96,6 +99,7 @@ public ChestSearchHack()
9699
addSetting(markXColor);
97100
addSetting(recordedChestNotifications);
98101
addSetting(lootMismatchNotifications);
102+
addSetting(consoleLogs);
99103
}
100104

101105
public int getMarkXColorARGB()
@@ -135,6 +139,11 @@ public boolean isLootMismatchNotificationEnabled()
135139
return lootMismatchNotifications.isChecked();
136140
}
137141

142+
public boolean shouldShowConsoleLogs()
143+
{
144+
return consoleLogs.isChecked();
145+
}
146+
138147
public int getCleanerGraceTicks()
139148
{
140149
return (int)(gracePeriodSec.getValueI() * 20);

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

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import net.minecraft.core.BlockPos;
1919
import net.minecraft.network.protocol.Packet;
2020
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
21+
import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
22+
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
2123
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
24+
import net.minecraft.core.registries.BuiltInRegistries;
2225
import net.minecraft.world.entity.Entity;
2326
import net.minecraft.world.entity.player.Player;
2427
import net.minecraft.world.phys.Vec3;
@@ -310,6 +313,20 @@ public void onReceivedPacket(PacketInputEvent event)
310313
if(packet instanceof ClientboundLevelEventPacket lvl)
311314
{
312315
handleLevelEvent(lvl);
316+
return;
317+
}
318+
319+
// Sound packets (used by some servers/versions for wither spawn
320+
// direction hints)
321+
if(packet instanceof ClientboundSoundPacket sound)
322+
{
323+
handleSoundPacket(sound);
324+
return;
325+
}
326+
327+
if(packet instanceof ClientboundSoundEntityPacket soundEntity)
328+
{
329+
handleSoundEntityPacket(soundEntity);
313330
}
314331
}catch(Throwable t)
315332
{
@@ -499,6 +516,83 @@ private void handleLevelEvent(ClientboundLevelEventPacket packet)
499516
}
500517
}
501518

519+
private void handleSoundPacket(ClientboundSoundPacket packet)
520+
{
521+
if(packet == null || MC == null || MC.player == null)
522+
return;
523+
if(!logMobs.isChecked())
524+
return;
525+
526+
String soundId;
527+
try
528+
{
529+
soundId = BuiltInRegistries.SOUND_EVENT
530+
.getKey(packet.getSound().value()).toString();
531+
}catch(Throwable t)
532+
{
533+
return;
534+
}
535+
536+
if(!"minecraft:entity.wither.spawn".equals(soundId))
537+
return;
538+
539+
Vec3 soundPos = new Vec3(packet.getX(), packet.getY(), packet.getZ());
540+
double dist = MC.player.position().distanceTo(soundPos);
541+
if(dist < minDistance.getValue())
542+
return;
543+
544+
String dir = getCompassDirection(MC.player.position(), soundPos);
545+
String msg = String.format(
546+
"[CoordLogger] Wither spawn sound at x=%.1f, y=%.1f, z=%.1f (dist=%.1f, dir=%s)",
547+
soundPos.x, soundPos.y, soundPos.z, dist, dir);
548+
MC.execute(() -> ChatUtils.message(msg));
549+
550+
boolean isFar = dist > NEAR_EVENT_DISTANCE;
551+
markers.add(new EventMarker(soundPos, isFar, 1023, "WITHER_SPAWN_SOUND",
552+
EventCategory.MOBS));
553+
}
554+
555+
private void handleSoundEntityPacket(ClientboundSoundEntityPacket packet)
556+
{
557+
if(packet == null || MC == null || MC.player == null
558+
|| MC.level == null)
559+
return;
560+
if(!logMobs.isChecked())
561+
return;
562+
563+
String soundId;
564+
try
565+
{
566+
soundId = BuiltInRegistries.SOUND_EVENT
567+
.getKey(packet.getSound().value()).toString();
568+
}catch(Throwable t)
569+
{
570+
return;
571+
}
572+
573+
if(!"minecraft:entity.wither.spawn".equals(soundId))
574+
return;
575+
576+
Entity entity = MC.level.getEntity(packet.getId());
577+
if(entity == null)
578+
return;
579+
580+
Vec3 soundPos = entity.position();
581+
double dist = MC.player.position().distanceTo(soundPos);
582+
if(dist < minDistance.getValue())
583+
return;
584+
585+
String dir = getCompassDirection(MC.player.position(), soundPos);
586+
String msg = String.format(
587+
"[CoordLogger] Wither spawn sound(entity) at x=%.1f, y=%.1f, z=%.1f (dist=%.1f, dir=%s)",
588+
soundPos.x, soundPos.y, soundPos.z, dist, dir);
589+
MC.execute(() -> ChatUtils.message(msg));
590+
591+
boolean isFar = dist > NEAR_EVENT_DISTANCE;
592+
markers.add(new EventMarker(soundPos, isFar, 1023,
593+
"WITHER_SPAWN_SOUND_ENTITY", EventCategory.MOBS));
594+
}
595+
502596
private double distanceToPlayer(BlockPos pos)
503597
{
504598
if(MC.player == null)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import net.wurstclient.hack.Hack;
1616
import net.wurstclient.lootsearch.LootChestManager;
1717
import net.wurstclient.lootsearch.LootSearchUtil;
18+
import net.wurstclient.settings.CheckboxSetting;
1819
import net.wurstclient.settings.FileSetting;
1920
import net.wurstclient.settings.SliderSetting;
2021
import net.wurstclient.settings.SliderSetting.ValueDisplay;
@@ -48,13 +49,19 @@ public final class LootSearchHack extends Hack
4849
ValueDisplay.INTEGER.withSuffix(" min")
4950
.withLabel(WAYPOINT_TIME_MINUTES_INFINITE, "Infinite"));
5051

52+
private final CheckboxSetting compareOpenedChests = new CheckboxSetting(
53+
"Compare opened chests",
54+
"Compare opened chests against the loot export and report mismatches.",
55+
false);
56+
5157
public LootSearchHack()
5258
{
5359
super("LootSearch");
5460
setCategory(Category.ITEMS);
5561
addSetting(lootJsonPicker);
5662
addSetting(literalJsonPath);
5763
addSetting(waypointTimeMinutes);
64+
addSetting(compareOpenedChests);
5865
}
5966

6067
public int getWaypointTimeMs()
@@ -65,6 +72,11 @@ public int getWaypointTimeMs()
6572
return minutes * 60 * 1000;
6673
}
6774

75+
public boolean shouldCompareOpenedChests()
76+
{
77+
return compareOpenedChests.isChecked();
78+
}
79+
6880
@Override
6981
protected void onEnable()
7082
{

0 commit comments

Comments
 (0)