Skip to content

Commit c2c30ce

Browse files
authored
[KillTheRNG] Remake for Fabric (#190)
2 parents 4eec8ca + 11396d8 commit c2c30ce

51 files changed

Lines changed: 1371 additions & 167 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ mod_email=scribble@minecrafttas.com
1919
# TASmod properties
2020
group=com.minecrafttas
2121
artifact=TASmod-1.12.2
22-
version=Beta2.2
22+
version=Beta3
2323
release=false

src/main/java/com/minecrafttas/mctcommon/events/EventListenerRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public interface EventBase {
9494
*/
9595
public static void register(EventBase eventListener) {
9696
if (eventListener == null) {
97-
throw new NullPointerException("Tried to register a packethandler with value null");
97+
throw new NullPointerException("Tried to register an eventListener with value null");
9898
}
9999

100100
for (Class<?> type : searchForInterfaces(eventListener.getClass())) {
@@ -153,7 +153,7 @@ public static void register(List<? extends EventBase> eventListeners) {
153153
*/
154154
public static void unregister(EventBase eventListener) {
155155
if (eventListener == null) {
156-
throw new NullPointerException("Tried to unregister a packethandler with value null");
156+
throw new NullPointerException("Tried to unregister an eventListener with value null");
157157
}
158158
for (Class<?> type : searchForInterfaces(eventListener.getClass())) {
159159
if (EventBase.class.isAssignableFrom(type)) {

src/main/java/com/minecrafttas/mctcommon/events/EventServer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
*/
1414
public interface EventServer {
1515

16+
/**
17+
* Fired, just before the server initialised, for both integrated and dedicated server.
18+
*/
19+
@FunctionalInterface
20+
public static interface EventServerStart extends EventBase {
21+
22+
/**
23+
* Fired, when the server is initialised, for both integrated and dedicated server.
24+
* @param server The server
25+
*/
26+
public void onServerStart(MinecraftServer server);
27+
}
28+
1629
/**
1730
* Fired, when the server is initialised, for both integrated and dedicated server.
1831
*/

src/main/java/com/minecrafttas/mctcommon/mixin/MixinMinecraftServer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
1010
import com.minecrafttas.mctcommon.events.EventServer.EventServerGameLoop;
1111
import com.minecrafttas.mctcommon.events.EventServer.EventServerInit;
12+
import com.minecrafttas.mctcommon.events.EventServer.EventServerStart;
1213
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
1314
import com.minecrafttas.mctcommon.events.EventServer.EventServerTick;
1415

@@ -17,6 +18,11 @@
1718
@Mixin(MinecraftServer.class)
1819
public class MixinMinecraftServer {
1920

21+
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z"))
22+
public void inject_initStart(CallbackInfo ci) {
23+
EventListenerRegistry.fireEvent(EventServerStart.class, (MinecraftServer) (Object) this);
24+
}
25+
2026
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z", shift = Shift.AFTER))
2127
public void inject_init(CallbackInfo ci) {
2228
EventListenerRegistry.fireEvent(EventServerInit.class, (MinecraftServer) (Object) this);

src/main/java/com/minecrafttas/tasmod/TASmod.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.minecrafttas.mctcommon.CommandRegistry;
99
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
1010
import com.minecrafttas.mctcommon.events.EventServer.EventServerInit;
11+
import com.minecrafttas.mctcommon.events.EventServer.EventServerStart;
1112
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
1213
import com.minecrafttas.mctcommon.networking.PacketHandlerRegistry;
1314
import com.minecrafttas.mctcommon.networking.Server;
@@ -24,6 +25,10 @@
2425
import com.minecrafttas.tasmod.commands.CommandSavestate;
2526
import com.minecrafttas.tasmod.commands.CommandTickrate;
2627
import com.minecrafttas.tasmod.handlers.PlayUntilHandler;
28+
import com.minecrafttas.tasmod.ktrng.GlobalRandomnessTimer;
29+
import com.minecrafttas.tasmod.ktrng.builtin.MathRandomness;
30+
import com.minecrafttas.tasmod.ktrng.builtin.WorldSeedRandomness;
31+
import com.minecrafttas.tasmod.ktrng.events.KillTheRNGMonitor;
2732
import com.minecrafttas.tasmod.playback.PlaybackControllerServer;
2833
import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension;
2934
import com.minecrafttas.tasmod.registries.TASmodAPIRegistry;
@@ -32,6 +37,7 @@
3237
import com.minecrafttas.tasmod.savestates.handlers.SavestateGuiHandlerServer;
3338
import com.minecrafttas.tasmod.savestates.handlers.SavestateResourcePackHandler;
3439
import com.minecrafttas.tasmod.savestates.storage.builtin.ClientMotionStorage;
40+
import com.minecrafttas.tasmod.savestates.storage.builtin.KTRNGSeedStorage;
3541
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer;
3642
import com.minecrafttas.tasmod.ticksync.TickSyncServer;
3743
import com.minecrafttas.tasmod.util.LoggerMarkers;
@@ -48,7 +54,7 @@
4854
*
4955
* @author Scribble
5056
*/
51-
public class TASmod implements ModInitializer, EventServerInit, EventServerStop {
57+
public class TASmod implements ModInitializer, EventServerStart, EventServerInit, EventServerStop {
5258

5359
public static final Logger LOGGER = LogManager.getLogger("TASmod");
5460

@@ -85,6 +91,16 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop
8591

8692
public static ClientMotionStorage motionStorage = new ClientMotionStorage();
8793

94+
public static GlobalRandomnessTimer globalRandomness;
95+
96+
public static KTRNGSeedStorage seedStorage = new KTRNGSeedStorage();
97+
98+
public static MathRandomness mathRandomness = new MathRandomness(0);
99+
100+
public static WorldSeedRandomness worldSeedRandomness = new WorldSeedRandomness(0);
101+
102+
public static KillTheRNGMonitor debugRand = new KillTheRNGMonitor();
103+
88104
@Override
89105
public void onInitialize() {
90106

@@ -111,6 +127,7 @@ public void onInitialize() {
111127
EventListenerRegistry.register(ticksyncServer);
112128
EventListenerRegistry.register(tickratechanger);
113129
// EventListenerRegistry.register(ktrngHandler);
130+
EventListenerRegistry.register(debugRand);
114131

115132
// Register packet handlers
116133
LOGGER.info(LoggerMarkers.Networking, "Registering network handlers");
@@ -128,12 +145,18 @@ public void onInitialize() {
128145
EventListenerRegistry.register(resourcepackHandler);
129146
PacketHandlerRegistry.register(playUntil);
130147
EventListenerRegistry.register(playUntil);
131-
132148
EventListenerRegistry.register(TASmodAPIRegistry.SAVESTATE_STORAGE);
133149

134150
registerSavestateStorage();
135151
}
136152

153+
@Override
154+
public void onServerStart(MinecraftServer server) {
155+
globalRandomness = new GlobalRandomnessTimer();
156+
EventListenerRegistry.register(globalRandomness);
157+
mathRandomness = new MathRandomness(0);
158+
}
159+
137160
@Override
138161
public void onServerInit(MinecraftServer server) {
139162
LOGGER.info("Initializing server");
@@ -196,6 +219,7 @@ public void onServerStop(MinecraftServer mcserver) {
196219

197220
private void registerSavestateStorage() {
198221
TASmodAPIRegistry.SAVESTATE_STORAGE.register(motionStorage);
222+
TASmodAPIRegistry.SAVESTATE_STORAGE.register(seedStorage);
199223
}
200224

201225
public static MinecraftServer getServerInstance() {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.minecrafttas.tasmod.events;
2+
3+
import com.minecrafttas.mctcommon.events.EventListenerRegistry.EventBase;
4+
import com.minecrafttas.tasmod.ktrng.RandomBase.RNGSide;
5+
6+
public interface EventKillTheRNGServer {
7+
8+
@FunctionalInterface
9+
public interface EventRNG extends EventBase {
10+
public void onRNGCall(RNGSide side, String eventType, long seed, String value, String rngClass);
11+
}
12+
}

src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,30 @@ interface EventServerSavestate extends EventBase {
2727
* Fired when loading a savestate, before the savestate folder is copied
2828
*/
2929
@FunctionalInterface
30-
interface EventServerLoadstate extends EventBase {
30+
interface EventServerLoadstatePre extends EventBase {
3131

3232
/**
3333
* Fired when loading a savestate, before the savestate folder is copied
3434
*
3535
* @param server The server instance
3636
* @param paths The {@link SavestatePaths} object
3737
*/
38-
public void onServerLoadstate(MinecraftServer server, SavestatePaths paths);
38+
public void onServerLoadstatePre(MinecraftServer server, SavestatePaths paths);
39+
}
40+
41+
/**
42+
* Fired when loading a savestate, after the savestate folder is copied
43+
*/
44+
@FunctionalInterface
45+
interface EventServerLoadstatePost extends EventBase {
46+
47+
/**
48+
* Fired when loading a savestate, after the savestate folder is copied
49+
*
50+
* @param server The server instance
51+
* @param paths The {@link SavestatePaths} object
52+
*/
53+
public void onServerLoadstatePost(MinecraftServer server, SavestatePaths paths);
3954
}
4055

4156
/**
@@ -47,7 +62,7 @@ interface EventServerCompleteLoadstate extends EventBase {
4762
/**
4863
* Fired one tick after a loadstate was carried out
4964
*/
50-
public void onServerLoadstateComplete();
65+
public void onServerLoadstateComplete(MinecraftServer server, SavestatePaths paths);
5166
}
5267

5368
/**

src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.minecrafttas.tasmod.TASmod;
1919
import com.minecrafttas.tasmod.TASmodClient;
2020
import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar;
21+
import com.minecrafttas.tasmod.ktrng.handlers.KTRNGWorldHandler;
2122
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
2223
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
2324
import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension;
@@ -295,17 +296,48 @@ public boolean checkInit() {
295296

296297
y += 14;
297298

298-
// if (TASmod.ktrngHandler.isLoaded()) {
299-
// title = "ktrng_randomseed";
300-
// if (configuration.getProperty(title + "_x", "err").equals("err"))
301-
// setDefaults(title, y);
302-
// lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title
303-
// + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
304-
// if (Minecraft.getMinecraft().currentScreen == this)
305-
// return "KTRNG";
306-
// return "RandomSeed: " + TASmod.ktrngHandler.getGlobalSeedClient();
307-
// }));
308-
// }
299+
title = "ktrng_randomseed";
300+
if (configuration.getProperty(title + "_x", "err").equals("err"))
301+
setDefaults(title, y);
302+
lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title
303+
+ "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
304+
if (Minecraft.getMinecraft().currentScreen == this)
305+
return "KTRNG";
306+
return "Global RandomSeed: " + TASmod.globalRandomness.getCurrentSeed();
307+
}));
308+
309+
// y += 14;
310+
// title = "ktrng_entitycount";
311+
// if (configuration.getProperty(title + "_x", "err").equals("err"))
312+
// setDefaults(title, y);
313+
// lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title
314+
// + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
315+
// if (Minecraft.getMinecraft().currentScreen == this)
316+
// return "EntityCount";
317+
// return "EntityCount: " + EntityRandomness.entityCounter;
318+
// }));
319+
320+
y += 14;
321+
title = "ktrng_worldseed";
322+
if (configuration.getProperty(title + "_x", "err").equals("err"))
323+
setDefaults(title, y);
324+
lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title
325+
+ "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
326+
if (Minecraft.getMinecraft().currentScreen == this)
327+
return "WorldRNG";
328+
return "WorldRNG: " + KTRNGWorldHandler.getWorldRandom();
329+
}));
330+
331+
y += 14;
332+
title = "ktrng_mathseed";
333+
if (configuration.getProperty(title + "_x", "err").equals("err"))
334+
setDefaults(title, y);
335+
lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title
336+
+ "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> {
337+
if (Minecraft.getMinecraft().currentScreen == this)
338+
return "MathRNG";
339+
return "MathRNG: " + TASmod.mathRandomness.getSeed();
340+
}));
309341

310342
title = "facing";
311343
y += 14;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.minecrafttas.tasmod.ktrng;
2+
3+
import com.minecrafttas.mctcommon.events.EventServer;
4+
5+
import kaptainwutax.seedutils.rand.JRand;
6+
import net.minecraft.server.MinecraftServer;
7+
8+
public class GlobalRandomnessTimer implements EventServer.EventServerTick {
9+
10+
private final JRand globalRandomness;
11+
12+
private long currentSeed = 0L;
13+
14+
public GlobalRandomnessTimer() {
15+
globalRandomness = new JRand(0L);
16+
}
17+
18+
@Override
19+
public void onServerTick(MinecraftServer server) {
20+
globalRandomness.advance(1);
21+
currentSeed = globalRandomness.getSeed();
22+
}
23+
24+
public long getCurrentSeed() {
25+
return currentSeed;
26+
}
27+
28+
public void setSeed(long newSeed) {
29+
globalRandomness.setSeed(newSeed);
30+
currentSeed = newSeed;
31+
}
32+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.minecrafttas.tasmod.ktrng;
2+
3+
import com.minecrafttas.mctcommon.events.EventClient;
4+
5+
import kaptainwutax.seedutils.rand.JRand;
6+
import net.minecraft.client.Minecraft;
7+
8+
public class GlobalRandomnessTimerClient implements EventClient.EventClientTick {
9+
10+
private final JRand globalRandomness;
11+
private final JRand uuidRandomness;
12+
13+
private long currentSeed = 0L;
14+
15+
public GlobalRandomnessTimerClient() {
16+
globalRandomness = new JRand(0L);
17+
uuidRandomness = new JRand(0L);
18+
}
19+
20+
@Override
21+
public void onClientTick(Minecraft mc) {
22+
currentSeed = globalRandomness.nextLong();
23+
uuidRandomness.setSeed(currentSeed);
24+
}
25+
26+
public long getCurrentSeed() {
27+
return currentSeed;
28+
}
29+
30+
public JRand getUUIDRandom() {
31+
return uuidRandomness;
32+
}
33+
34+
public void setSeed(long newSeed) {
35+
globalRandomness.setSeed(newSeed);
36+
currentSeed = newSeed;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)