Skip to content

Commit 0fe9e70

Browse files
committed
Auto Save/Apply SeedCracker Seed
1 parent 3f9b8a8 commit 0fe9e70

File tree

6 files changed

+117
-4
lines changed

6 files changed

+117
-4
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ This change was accepted upstream, however in my fork I have adjusted the size o
2626

2727
### World Presets
2828

29-
If the server you're on uses anything other than the default world preset (Large Biomes, Single Biome, ~~Amplified~~, ~~Superflat~~) this will greatly change the world generation. Change the preset to match the server in order to produce an accurate seedmap. Note that Amplified and Superflat biomes are not implemented yet and are placeholders.
29+
If the server you're on uses anything other than the default world preset (Large Biomes, Single Biome, ~~Amplified~~, ~~Superflat~~) this will greatly change the world generation. Change the preset to match the server in order to produce an accurate seedmap.
30+
31+
Note that Amplified and Superflat biomes are not implemented yet and are placeholders.
3032

3133
- ```/sm:preset list``` — show available presets
3234
- ```/sm:preset set <id>``` — set SeedMapper’s preset
@@ -74,7 +76,7 @@ This has now been implemented by upstream. They have unified both End City Ships
7476
### Improved ESP
7577
Configurable ESP settings allowing for custom colors, fill and transparency.
7678

77-
Example: ```/sm:config blockhighlightesp set outlineColor #ff0000 outlineAlpha 0.5 fillEnabled true fillColor #00ff00 fillAlpha 0.35```
79+
Example: ```/sm:config BlockHighlightESP set outlineColor #ff0000 outlineAlpha 0.5 fillEnabled true fillColor #00ff00 fillAlpha 0.35```
7880

7981
![ESP](https://i.imgur.com/S9KeYpR.png)
8082

@@ -86,10 +88,14 @@ Can now finally remove SeedMapper waypoints with via a right click context menu.
8688
![Map](https://i.imgur.com/1qDgQw7.png)
8789

8890
### Highlight Timeout Setting
89-
Can now change the default 5 minute render timeout with ```/sm:config esptimeoutminutes```
91+
Can now change the default 5 minute render timeout with ```/sm:config EspTimeoutMinutes```
9092

9193
### Export Loot Table
9294
Can now export the entire loot table for the map you're viewing by clicking ```Export Loot``` or via commands such as ```/sm:exportLoot <radius> [dimension] [structures/all]```.
9395

9496
Exported data will be located in ```SeedMapper/loot/<Server IP>_<Seed>-<Date/Time>.json```
9597

98+
### Auto Apply SeedCracker Seed
99+
If the server you're in already has a seed in the database it will be auto applied and saved.
100+
101+
You can enable/disable this with ```/sm:config AutoApplySeedCrackerSeed true/false```

src/main/java/dev/xpple/seedmapper/config/Configs.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import net.minecraft.util.Util;
1414
import dev.xpple.seedmapper.render.esp.EspStyle;
1515

16+
import java.net.SocketAddress;
1617
import java.util.EnumSet;
1718
import java.util.HashMap;
1819
import java.util.Map;
20+
import java.util.Objects;
1921
import java.util.function.Supplier;
2022

2123
import static dev.xpple.seedmapper.util.ChatBuilder.*;
@@ -34,10 +36,52 @@ public static void save() {
3436
@Config(putter = @Config.Putter("none"), adder = @Config.Adder(value = "addSavedSeed", type = long.class))
3537
public static Map<String, Long> SavedSeeds = new HashMap<>();
3638
private static void addSavedSeed(long seed) {
37-
String key = Minecraft.getInstance().getConnection().getConnection().getRemoteAddress().toString();
39+
String key = getCurrentServerKey();
40+
if (key == null) {
41+
return;
42+
}
3843
SavedSeeds.put(key, seed);
3944
}
4045

46+
@Config
47+
public static boolean AutoApplySeedCrackerSeed = true;
48+
49+
private static String getCurrentServerKey() {
50+
Minecraft minecraft = Minecraft.getInstance();
51+
if (minecraft == null || minecraft.getConnection() == null || minecraft.getConnection().getConnection() == null) {
52+
return null;
53+
}
54+
SocketAddress remoteAddress = minecraft.getConnection().getConnection().getRemoteAddress();
55+
return remoteAddress != null ? remoteAddress.toString() : null;
56+
}
57+
58+
public static void applySeedForCurrentServer(long seed, boolean storeAsSavedSeed) {
59+
String key = getCurrentServerKey();
60+
boolean changed = false;
61+
if (storeAsSavedSeed && key != null && !Objects.equals(SavedSeeds.get(key), seed)) {
62+
SavedSeeds.put(key, seed);
63+
changed = true;
64+
}
65+
if (!Objects.equals(Seed, seed)) {
66+
Seed = seed;
67+
changed = true;
68+
}
69+
if (changed) {
70+
save();
71+
}
72+
}
73+
74+
public static void loadSavedSeedForCurrentServer() {
75+
String key = getCurrentServerKey();
76+
if (key == null) {
77+
return;
78+
}
79+
Long savedSeed = SavedSeeds.get(key);
80+
if (savedSeed != null) {
81+
applySeedForCurrentServer(savedSeed, false);
82+
}
83+
}
84+
4185
@Config
4286
public static SeedResolutionArgument.SeedResolution SeedResolutionOrder = new SeedResolutionArgument.SeedResolution();
4387

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dev.xpple.seedmapper.mixin;
2+
3+
import dev.xpple.seedmapper.util.SavedSeedChatCatcher;
4+
import net.minecraft.client.GuiMessageTag;
5+
import net.minecraft.client.gui.components.ChatComponent;
6+
import net.minecraft.network.chat.Component;
7+
import net.minecraft.network.chat.MessageSignature;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(ChatComponent.class)
14+
public class ChatComponentMixin {
15+
16+
@Inject(method = "addMessage(Lnet/minecraft/network/chat/Component;)V", at = @At("HEAD"))
17+
private void seedmapper$captureSimple(Component component, CallbackInfo ci) {
18+
SavedSeedChatCatcher.capture(component);
19+
}
20+
21+
@Inject(method = "addMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/MessageSignature;Lnet/minecraft/client/GuiMessageTag;)V", at = @At("HEAD"))
22+
private void seedmapper$captureSigned(Component component, MessageSignature signature, GuiMessageTag tag, CallbackInfo ci) {
23+
SavedSeedChatCatcher.capture(component);
24+
}
25+
}

src/main/java/dev/xpple/seedmapper/mixin/ClientPacketListenerMixin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dev.xpple.seedmapper.mixin;
22

3+
import dev.xpple.seedmapper.config.Configs;
34
import dev.xpple.seedmapper.render.RenderManager;
45
import net.minecraft.client.multiplayer.ClientPacketListener;
56
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
@@ -16,6 +17,11 @@ private void onHandleLogin(ClientboundLoginPacket packet, CallbackInfo ci) {
1617
RenderManager.clear();
1718
}
1819

20+
@Inject(method = "handleLogin", at = @At("TAIL"))
21+
private void seedmapper$applySavedSeed(ClientboundLoginPacket packet, CallbackInfo ci) {
22+
Configs.loadSavedSeedForCurrentServer();
23+
}
24+
1925
@Inject(method = "handleRespawn", at = @At("HEAD"))
2026
private void onHandleRespawn(ClientboundRespawnPacket packet, CallbackInfo ci) {
2127
RenderManager.clear();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.xpple.seedmapper.util;
2+
3+
import dev.xpple.seedmapper.config.Configs;
4+
import net.minecraft.network.chat.Component;
5+
6+
import java.util.regex.Matcher;
7+
import java.util.regex.Pattern;
8+
9+
public final class SavedSeedChatCatcher {
10+
11+
private static final Pattern FOUND_SEED_PATTERN = Pattern.compile("(?i)found world seed \\[(-?\\d+)]\\s+from database");
12+
13+
private SavedSeedChatCatcher() {
14+
}
15+
16+
public static void capture(Component component) {
17+
if (component == null || !Configs.AutoApplySeedCrackerSeed) {
18+
return;
19+
}
20+
String plain = component.getString();
21+
Matcher matcher = FOUND_SEED_PATTERN.matcher(plain);
22+
if (!matcher.find()) {
23+
return;
24+
}
25+
try {
26+
long seed = Long.parseLong(matcher.group(1));
27+
Configs.applySeedForCurrentServer(seed, true);
28+
} catch (NumberFormatException ignored) {
29+
}
30+
}
31+
}

src/main/resources/mixins.seedmapper.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"package": "dev.xpple.seedmapper.mixin",
44
"compatibilityLevel": "JAVA_21",
55
"client": [
6+
"ChatComponentMixin",
67
"ClientPacketListenerMixin",
78
"ChatScreenMixin",
89
"betterconfig.ConfigCommandClientMixin"

0 commit comments

Comments
 (0)