From 60eef7d0d6e895089cfcb8d598cc4de6a3906bc9 Mon Sep 17 00:00:00 2001 From: Scribble Date: Sat, 6 Jan 2024 13:42:33 +0100 Subject: [PATCH 01/26] [KillTheRNG] Added random seed display above entities --- .../killtherng/mixin/MixinRender.java | 35 +++++++++++++++++++ .../tasmod/ktrng/KillTheRNGHandler.java | 1 - src/main/resources/fabric.mod.json | 3 +- src/main/resources/killtherng.mixin.json | 13 +++++++ src/main/resources/tasmod.accesswidener | 5 ++- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java create mode 100644 src/main/resources/killtherng.mixin.json diff --git a/src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java b/src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java new file mode 100644 index 00000000..c5992bc8 --- /dev/null +++ b/src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java @@ -0,0 +1,35 @@ +package com.minecrafttas.killtherng.mixin; + +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderLivingBase; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.EntityLivingBase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.Random; + +@Mixin(RenderLivingBase.class) +public abstract class MixinRender extends Render { + protected MixinRender(RenderManager renderManager) { + super(renderManager); + } + + @Inject(method = "renderName", at = @At(value = "HEAD")) + public void inject_renderName(EntityLivingBase entity, double d, double e, double f, CallbackInfo ci){ + long seed = getSeed(entity.rand); + GlStateManager.alphaFunc(516, 0.1F); + this.renderEntityName(entity, d, e+0.23D, f, Long.toString(seed), 64); + } + + private long getSeed(Random rand) { + long in = rand.nextLong(); + long seed = (((7847617*((24667315*(in >>> 32) + 18218081*(in & 0xffffffffL) + 67552711) >> 32) - 18218081*((-4824621*(in >>> 32) + 7847617*(in & 0xffffffffL) + 7847617) >> 32)) - 11) * 246154705703781L) & 0xffffffffffffL; + seed = seed ^ 0x5deece66dL; + rand.setSeed(seed); + return seed; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java index d071cd81..18926f41 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java @@ -40,7 +40,6 @@ public class KillTheRNGHandler implements EventServerTick, EventPlayerJoinedClie * @param isLoaded If the KillTheRNG mod is loaded */ public KillTheRNGHandler(boolean isLoaded) { - this.isLoaded = isLoaded; if (isLoaded) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2a4bea59..a6de6ad7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,8 +26,9 @@ ] }, "mixins": [ + "mctcommon.mixin.json", "tasmod.mixin.json", - "mctcommon.mixin.json" + "killtherng.mixin.json" ], "depends": { "fabricloader": ">=0.14.19", diff --git a/src/main/resources/killtherng.mixin.json b/src/main/resources/killtherng.mixin.json new file mode 100644 index 00000000..6ac449d1 --- /dev/null +++ b/src/main/resources/killtherng.mixin.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8.5", + "package": "com.minecrafttas.killtherng.mixin", + "refmap": "tasmod.refmap.json", + "compatibilityLevel": "JAVA_8", + "mixins": [ + + ], + "client": [ + "MixinRender" + ] +} \ No newline at end of file diff --git a/src/main/resources/tasmod.accesswidener b/src/main/resources/tasmod.accesswidener index 0029bc11..7d539c92 100644 --- a/src/main/resources/tasmod.accesswidener +++ b/src/main/resources/tasmod.accesswidener @@ -11,4 +11,7 @@ accessible field net/minecraft/world/World worldInfo Lnet/minecraft/world/storag accessible method net/minecraft/world/storage/SaveHandler setSessionLock ()V -accessible field net/minecraft/client/settings/KeyBinding CATEGORY_ORDER Ljava/util/Map; \ No newline at end of file +accessible field net/minecraft/client/settings/KeyBinding CATEGORY_ORDER Ljava/util/Map; + +#KillTheRNG +accessible field net/minecraft/entity/Entity rand Ljava/util/Random; \ No newline at end of file From 064b2f746493995cac74e4463e8b2bbb9d0111f2 Mon Sep 17 00:00:00 2001 From: Scribble Date: Wed, 6 Aug 2025 20:59:11 +0200 Subject: [PATCH 02/26] [KillTheRNG] Cleanup files - Add CustomRandom from old mod - Update MixinRender - Remove seperate mixin.json --- .../killtherng/mixin/MixinRender.java | 35 ---- .../tasmod/ktrng/KTRNGRandom.java | 180 ++++++++++++++++++ .../killtherng/MixinRenderLivingBase.java | 40 ++++ src/main/resources/fabric.mod.json | 3 +- src/main/resources/killtherng.mixin.json | 13 -- src/main/resources/tasmod.mixin.json | 5 +- 6 files changed, 225 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGRandom.java create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java delete mode 100644 src/main/resources/killtherng.mixin.json diff --git a/src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java b/src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java deleted file mode 100644 index c5992bc8..00000000 --- a/src/main/java/com/minecrafttas/killtherng/mixin/MixinRender.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.minecrafttas.killtherng.mixin; - -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.entity.Render; -import net.minecraft.client.renderer.entity.RenderLivingBase; -import net.minecraft.client.renderer.entity.RenderManager; -import net.minecraft.entity.EntityLivingBase; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Random; - -@Mixin(RenderLivingBase.class) -public abstract class MixinRender extends Render { - protected MixinRender(RenderManager renderManager) { - super(renderManager); - } - - @Inject(method = "renderName", at = @At(value = "HEAD")) - public void inject_renderName(EntityLivingBase entity, double d, double e, double f, CallbackInfo ci){ - long seed = getSeed(entity.rand); - GlStateManager.alphaFunc(516, 0.1F); - this.renderEntityName(entity, d, e+0.23D, f, Long.toString(seed), 64); - } - - private long getSeed(Random rand) { - long in = rand.nextLong(); - long seed = (((7847617*((24667315*(in >>> 32) + 18218081*(in & 0xffffffffL) + 67552711) >> 32) - 18218081*((-4824621*(in >>> 32) + 7847617*(in & 0xffffffffL) + 7847617) >> 32)) - 11) * 246154705703781L) & 0xffffffffffffL; - seed = seed ^ 0x5deece66dL; - rand.setSeed(seed); - return seed; - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGRandom.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGRandom.java new file mode 100644 index 00000000..f065bf92 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGRandom.java @@ -0,0 +1,180 @@ +package com.minecrafttas.tasmod.ktrng; + +import java.util.Random; + +import kaptainwutax.seedutils.lcg.LCG; +import kaptainwutax.seedutils.rand.JRand; + +public class KTRNGRandom extends Random { + + private String name; + private String description; + + private long timesCalled = 0; + + private boolean enabled; + private boolean client; + + public KTRNGRandom(String name, String description, boolean enabled, boolean client) { + super(0L); + this.name = name; + this.description = description; + this.enabled = enabled; + this.client = client; + } + + public void setSeed(long seedIn) { + timesCalled = 0; + super.setSeed(seedIn ^ 0x5deece66dL); + } + + public void setSeed(long seedIn, boolean shouldIncrease) { + timesCalled++; + super.setSeed(seedIn ^ 0x5deece66dL); + } + + public long getSeed() { + long saved = timesCalled; + long seed = reverse(super.nextLong()) ^ 0x5deece66dL; + super.setSeed(seed); + timesCalled = saved; + return seed ^ 0x5deece66dL; + } + + public static long reverse(long in) { + return (((7847617 * ((24667315 * (in >>> 32) + 18218081 * (in & 0xffffffffL) + 67552711) >> 32) - 18218081 * ((-4824621 * (in >>> 32) + 7847617 * (in & 0xffffffffL) + 7847617) >> 32)) - 11) * 246154705703781L) & 0xffffffffffffL; + } + + public String getName() { + return this.name; + } + + public String getDescription() { + return description; + } + + public long getTimesCalled() { + return timesCalled; + } + + public boolean isEnabled() { + return enabled; + } + + public boolean isClient() { + return client; + } + + @Override + public long nextLong() { + timesCalled++; + long seedstored = getSeed(); + long value = super.nextLong(); + fireEvent(seedstored, Long.toString(value)); + return value; + } + + @Override + public double nextDouble() { + timesCalled++; + long seedstored = getSeed(); + double value = super.nextDouble(); + fireEvent(seedstored, Double.toString(value)); + return value; + } + + @Override + public boolean nextBoolean() { + timesCalled++; + long seedstored = getSeed(); + boolean value = super.nextBoolean(); + fireEvent(seedstored, Boolean.toString(value)); + return value; + } + + @Override + public int nextInt() { + timesCalled++; + long seedstored = getSeed(); + int value = super.nextInt(); + fireEvent(seedstored, Integer.toString(value)); + return value; + } + + @Override + public int nextInt(int bound) { + timesCalled++; + long seedstored = getSeed(); + int value = super.nextInt(bound); + fireEvent(seedstored, Integer.toString(value)); + return value; + } + + @Override + public float nextFloat() { + return super.nextFloat(); + } + + @Override + public void nextBytes(byte[] bytes) { + super.nextBytes(bytes); + } + + @Override + public double nextGaussian() { + timesCalled++; + double value = 0; + value = super.nextGaussian(); + return value; + } + + public void advance() { + advance(1); + } + + public void advance(long i) { + JRand thing = JRand.ofInternalSeed(getSeed()); + thing.advance(i); + setSeed(thing.getSeed()); + } + + public long getSeedAt(int steps) { + JRand thing = new JRand(getSeed()).combine(steps); + return thing.getSeed(); + } + + public long distance(KTRNGRandom random) { + return KTRNGRandom.distance(this.getSeed(), random.getSeed()); + } + + public long distance(long seed) { + return KTRNGRandom.distance(this.getSeed(), seed); + } + + public static long distance(KTRNGRandom random1, KTRNGRandom random2) { + return KTRNGRandom.distance(random1.getSeed(), random2.getSeed()); + } + + public static long distance(long seed, long seed2) { + return LCG.JAVA.distance(seed, seed2); + } + + @Override + public String toString() { + return name + ": " + enabled; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof KTRNGRandom) { + KTRNGRandom custom = (KTRNGRandom) obj; + return custom.name.equals(name); + } else { + return super.equals(obj); + } + } + + public void fireEvent(long seed, String value) { + // TODO Implement + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java new file mode 100644 index 00000000..25f2ea2c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java @@ -0,0 +1,40 @@ +package com.minecrafttas.tasmod.mixin.killtherng; + +import java.util.Random; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderLivingBase; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.EntityLivingBase; + +@SuppressWarnings("rawtypes") +@Mixin(RenderLivingBase.class) +public abstract class MixinRenderLivingBase extends Render { + + protected MixinRenderLivingBase(RenderManager renderManager) { + super(renderManager); + } + + @SuppressWarnings("unchecked") + @Inject(method = "renderName", at = @At(value = "HEAD")) + public void inject_renderName(EntityLivingBase entity, double d, double e, double f, CallbackInfo ci) { + long seed = getSeed(entity.rand); + GlStateManager.alphaFunc(516, 0.1F); + this.renderEntityName(entity, d, e + 0.23D, f, Long.toString(seed), 64); + } + + private long getSeed(Random rand) { + long in = rand.nextLong(); + long seed = (((7847617 * ((24667315 * (in >>> 32) + 18218081 * (in & 0xffffffffL) + 67552711) >> 32) - 18218081 * ((-4824621 * (in >>> 32) + 7847617 * (in & 0xffffffffL) + 7847617) >> 32)) - 11) * 246154705703781L) + & 0xffffffffffffL; + seed = seed ^ 0x5deece66dL; + rand.setSeed(seed); + return seed; + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a6de6ad7..105e907c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,8 +27,7 @@ }, "mixins": [ "mctcommon.mixin.json", - "tasmod.mixin.json", - "killtherng.mixin.json" + "tasmod.mixin.json" ], "depends": { "fabricloader": ">=0.14.19", diff --git a/src/main/resources/killtherng.mixin.json b/src/main/resources/killtherng.mixin.json deleted file mode 100644 index 6ac449d1..00000000 --- a/src/main/resources/killtherng.mixin.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8.5", - "package": "com.minecrafttas.killtherng.mixin", - "refmap": "tasmod.refmap.json", - "compatibilityLevel": "JAVA_8", - "mixins": [ - - ], - "client": [ - "MixinRender" - ] -} \ No newline at end of file diff --git a/src/main/resources/tasmod.mixin.json b/src/main/resources/tasmod.mixin.json index b500e7d6..362c340c 100644 --- a/src/main/resources/tasmod.mixin.json +++ b/src/main/resources/tasmod.mixin.json @@ -68,6 +68,9 @@ // Fixes "fixes.MixinMinecraftFullscreen", "fixes.MixinNetworkManager", - "fixes.MixinMouseHelper" + "fixes.MixinMouseHelper", + + // KTRNG + "killtherng.MixinRenderLivingBase" ] } \ No newline at end of file From e1241221cdc1e4a396cd9253b81040175caf2122 Mon Sep 17 00:00:00 2001 From: Scribble Date: Thu, 11 Sep 2025 15:11:05 +0200 Subject: [PATCH 03/26] [KillTheRNG] Add testing code --- .../tasmod/mixin/killtherng/MixinEntity.java | 20 +++++++++++++++ .../killtherng/MixinRenderLivingBase.java | 25 ++++++++++--------- .../tasmod/registries/TASmodKeybinds.java | 7 +++++- src/main/resources/tasmod.mixin.json | 4 ++- 4 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java new file mode 100644 index 00000000..0bb36b44 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java @@ -0,0 +1,20 @@ +package com.minecrafttas.tasmod.mixin.killtherng; + +import java.util.Random; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.minecrafttas.tasmod.ktrng.KTRNGRandom; + +import net.minecraft.entity.Entity; + +@Mixin(Entity.class) +public class MixinEntity { + + @ModifyExpressionValue(method = "", at = @At(value = "NEW", target = "Ljava/util/Random;")) + public Random modify_entityRandom(Random original) { + return new KTRNGRandom("What", "What", true, false); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java index 25f2ea2c..4af2d282 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java @@ -1,22 +1,28 @@ package com.minecrafttas.tasmod.mixin.killtherng; -import java.util.Random; - import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.ktrng.KTRNGRandom; + import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.entity.RenderLivingBase; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; @SuppressWarnings("rawtypes") @Mixin(RenderLivingBase.class) public abstract class MixinRenderLivingBase extends Render { + @Unique + private long previousSeed = 0; + protected MixinRenderLivingBase(RenderManager renderManager) { super(renderManager); } @@ -24,17 +30,12 @@ protected MixinRenderLivingBase(RenderManager renderManager) { @SuppressWarnings("unchecked") @Inject(method = "renderName", at = @At(value = "HEAD")) public void inject_renderName(EntityLivingBase entity, double d, double e, double f, CallbackInfo ci) { - long seed = getSeed(entity.rand); + Entity serverEntity = TASmod.getServerInstance().getEntityFromUuid(entity.getUniqueID()); + KTRNGRandom random = (KTRNGRandom) serverEntity.rand; + long seed = random.getSeed(); + long distance = -random.distance(previousSeed); GlStateManager.alphaFunc(516, 0.1F); this.renderEntityName(entity, d, e + 0.23D, f, Long.toString(seed), 64); - } - - private long getSeed(Random rand) { - long in = rand.nextLong(); - long seed = (((7847617 * ((24667315 * (in >>> 32) + 18218081 * (in & 0xffffffffL) + 67552711) >> 32) - 18218081 * ((-4824621 * (in >>> 32) + 7847617 * (in & 0xffffffffL) + 7847617) >> 32)) - 11) * 246154705703781L) - & 0xffffffffffffL; - seed = seed ^ 0x5deece66dL; - rand.setSeed(seed); - return seed; + this.renderEntityName(entity, d, e + 0D, f, Long.toString(distance), 64); } } diff --git a/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java b/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java index 7c486dbf..fd85aaf1 100644 --- a/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java +++ b/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java @@ -5,7 +5,9 @@ import com.minecrafttas.mctcommon.KeybindManager.IsKeyDownFunc; import com.minecrafttas.mctcommon.KeybindManager.Keybind; import com.minecrafttas.mctcommon.KeybindManager.KeybindID; +import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.TASmodClient; +import com.minecrafttas.tasmod.ktrng.KTRNGRandom; import com.minecrafttas.tasmod.networking.TASmodBufferBuilder; import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; import com.minecrafttas.tasmod.virtual.VirtualKeybindings; @@ -46,7 +48,10 @@ public enum TASmodKeybinds implements KeybindID { TASmodClient.virtual.CAMERA_ANGLE.updateNextCameraAngle(0, 45); }), TEST1("Various Testing", "TASmod", Keyboard.KEY_F12, () -> { - Minecraft.getMinecraft().displayGuiScreen(null); + TASmod.getServerInstance().getEntityWorld().loadedEntityList.forEach(entity -> { + KTRNGRandom rand = (KTRNGRandom) entity.rand; + rand.setSeed(0); + }); }, VirtualKeybindings::isKeyDown), TEST2("Various Testing2", "TASmod", Keyboard.KEY_F7, () -> { }, VirtualKeybindings::isKeyDown); diff --git a/src/main/resources/tasmod.mixin.json b/src/main/resources/tasmod.mixin.json index 362c340c..f648916f 100644 --- a/src/main/resources/tasmod.mixin.json +++ b/src/main/resources/tasmod.mixin.json @@ -21,7 +21,9 @@ "events.MixinEntityPlayerMP", // Fixing forge and vanilla stuff - "fixes.MixinDragonFightManager" + "fixes.MixinDragonFightManager", + + "killtherng.MixinEntity" ], "client": [ From 67bc05bb2fc2f8848f7b485cc881820c6b939f07 Mon Sep 17 00:00:00 2001 From: Scribble Date: Thu, 11 Sep 2025 20:26:50 +0200 Subject: [PATCH 04/26] [KillTheRNG] Adding global randomness timer --- .../events/EventListenerRegistry.java | 4 +-- .../java/com/minecrafttas/tasmod/TASmod.java | 6 ++++ .../tasmod/ktrng/EntityRandomness.java | 12 +++++++ .../tasmod/ktrng/GlobalRandomnessTimer.java | 25 +++++++++++++++ .../{KTRNGRandom.java => RandomBase.java} | 31 ++++++++++--------- .../tasmod/mixin/killtherng/MixinEntity.java | 4 +-- .../killtherng/MixinRenderLivingBase.java | 10 +++--- .../tasmod/registries/TASmodKeybinds.java | 4 +-- 8 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java rename src/main/java/com/minecrafttas/tasmod/ktrng/{KTRNGRandom.java => RandomBase.java} (83%) diff --git a/src/main/java/com/minecrafttas/mctcommon/events/EventListenerRegistry.java b/src/main/java/com/minecrafttas/mctcommon/events/EventListenerRegistry.java index 1170342e..03d5c1f4 100644 --- a/src/main/java/com/minecrafttas/mctcommon/events/EventListenerRegistry.java +++ b/src/main/java/com/minecrafttas/mctcommon/events/EventListenerRegistry.java @@ -94,7 +94,7 @@ public interface EventBase { */ public static void register(EventBase eventListener) { if (eventListener == null) { - throw new NullPointerException("Tried to register a packethandler with value null"); + throw new NullPointerException("Tried to register an eventListener with value null"); } for (Class type : searchForInterfaces(eventListener.getClass())) { @@ -153,7 +153,7 @@ public static void register(List eventListeners) { */ public static void unregister(EventBase eventListener) { if (eventListener == null) { - throw new NullPointerException("Tried to unregister a packethandler with value null"); + throw new NullPointerException("Tried to unregister an eventListener with value null"); } for (Class type : searchForInterfaces(eventListener.getClass())) { if (EventBase.class.isAssignableFrom(type)) { diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index 51700db5..41daeb4f 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -24,6 +24,7 @@ import com.minecrafttas.tasmod.commands.CommandSavestate; import com.minecrafttas.tasmod.commands.CommandTickrate; import com.minecrafttas.tasmod.handlers.PlayUntilHandler; +import com.minecrafttas.tasmod.ktrng.GlobalRandomnessTimer; import com.minecrafttas.tasmod.playback.PlaybackControllerServer; import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension; import com.minecrafttas.tasmod.registries.TASmodAPIRegistry; @@ -85,6 +86,8 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop public static ClientMotionStorage motionStorage = new ClientMotionStorage(); + public static GlobalRandomnessTimer globalRandomness; + @Override public void onInitialize() { @@ -159,6 +162,9 @@ public void onServerInit(MinecraftServer server) { PacketHandlerRegistry.register(savestateHandlerServer.getPlayerHandler()); EventListenerRegistry.register(savestateHandlerServer.getSavestateTemporaryHandler()); + globalRandomness = new GlobalRandomnessTimer(); + EventListenerRegistry.register(globalRandomness); + if (!server.isDedicatedServer()) { TASmod.tickratechanger.ticksPerSecond = 0F; TASmod.tickratechanger.tickrateSaved = 20F; diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java new file mode 100644 index 00000000..a84cf77e --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java @@ -0,0 +1,12 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.tasmod.TASmod; + +public class EntityRandomness extends RandomBase { + + private static long entityCounter = 0L; + + public EntityRandomness() { + super(TASmod.globalRandomness.getCurrentSeed() + (entityCounter++)); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java new file mode 100644 index 00000000..48faff67 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java @@ -0,0 +1,25 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.mctcommon.events.EventServer; + +import net.minecraft.server.MinecraftServer; + +public class GlobalRandomnessTimer implements EventServer.EventServerTick { + + private RandomBase globalRandomness; + + private long currentSeed = 0L; + + public GlobalRandomnessTimer() { + globalRandomness = new RandomBase(0L); + } + + @Override + public void onServerTick(MinecraftServer server) { + currentSeed = globalRandomness.nextLong(); + } + + public long getCurrentSeed() { + return currentSeed; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGRandom.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java similarity index 83% rename from src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGRandom.java rename to src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index f065bf92..6e609100 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGRandom.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -5,7 +5,7 @@ import kaptainwutax.seedutils.lcg.LCG; import kaptainwutax.seedutils.rand.JRand; -public class KTRNGRandom extends Random { +public class RandomBase extends Random { private String name; private String description; @@ -15,12 +15,11 @@ public class KTRNGRandom extends Random { private boolean enabled; private boolean client; - public KTRNGRandom(String name, String description, boolean enabled, boolean client) { - super(0L); - this.name = name; - this.description = description; - this.enabled = enabled; - this.client = client; + private long initialSeed; + + public RandomBase(long seed) { + super(seed); + this.initialSeed = seed; } public void setSeed(long seedIn) { @@ -143,16 +142,16 @@ public long getSeedAt(int steps) { return thing.getSeed(); } - public long distance(KTRNGRandom random) { - return KTRNGRandom.distance(this.getSeed(), random.getSeed()); + public long distance(RandomBase random) { + return RandomBase.distance(this.getSeed(), random.getSeed()); } public long distance(long seed) { - return KTRNGRandom.distance(this.getSeed(), seed); + return RandomBase.distance(this.getSeed(), seed); } - public static long distance(KTRNGRandom random1, KTRNGRandom random2) { - return KTRNGRandom.distance(random1.getSeed(), random2.getSeed()); + public static long distance(RandomBase random1, RandomBase random2) { + return RandomBase.distance(random1.getSeed(), random2.getSeed()); } public static long distance(long seed, long seed2) { @@ -166,8 +165,8 @@ public String toString() { @Override public boolean equals(Object obj) { - if (obj instanceof KTRNGRandom) { - KTRNGRandom custom = (KTRNGRandom) obj; + if (obj instanceof RandomBase) { + RandomBase custom = (RandomBase) obj; return custom.name.equals(name); } else { return super.equals(obj); @@ -177,4 +176,8 @@ public boolean equals(Object obj) { public void fireEvent(long seed, String value) { // TODO Implement } + + public long getInitialSeed() { + return initialSeed; + } } diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java index 0bb36b44..89b3f9ce 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java @@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.injection.At; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import com.minecrafttas.tasmod.ktrng.KTRNGRandom; +import com.minecrafttas.tasmod.ktrng.EntityRandomness; import net.minecraft.entity.Entity; @@ -15,6 +15,6 @@ public class MixinEntity { @ModifyExpressionValue(method = "", at = @At(value = "NEW", target = "Ljava/util/Random;")) public Random modify_entityRandom(Random original) { - return new KTRNGRandom("What", "What", true, false); + return new EntityRandomness(); } } diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java index 4af2d282..49b07a4f 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java @@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.ktrng.KTRNGRandom; +import com.minecrafttas.tasmod.ktrng.RandomBase; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.Render; @@ -31,11 +31,11 @@ protected MixinRenderLivingBase(RenderManager renderManager) { @Inject(method = "renderName", at = @At(value = "HEAD")) public void inject_renderName(EntityLivingBase entity, double d, double e, double f, CallbackInfo ci) { Entity serverEntity = TASmod.getServerInstance().getEntityFromUuid(entity.getUniqueID()); - KTRNGRandom random = (KTRNGRandom) serverEntity.rand; + RandomBase random = (RandomBase) serverEntity.rand; long seed = random.getSeed(); - long distance = -random.distance(previousSeed); + long distance = -random.distance(random.getInitialSeed()); GlStateManager.alphaFunc(516, 0.1F); - this.renderEntityName(entity, d, e + 0.23D, f, Long.toString(seed), 64); - this.renderEntityName(entity, d, e + 0D, f, Long.toString(distance), 64); + this.renderEntityName(entity, d, e + 0.46D, f, Long.toString(seed), 64); + this.renderEntityName(entity, d, e + 0.23D, f, Long.toString(distance), 64); } } diff --git a/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java b/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java index fd85aaf1..c60347da 100644 --- a/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java +++ b/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java @@ -7,7 +7,7 @@ import com.minecrafttas.mctcommon.KeybindManager.KeybindID; import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.TASmodClient; -import com.minecrafttas.tasmod.ktrng.KTRNGRandom; +import com.minecrafttas.tasmod.ktrng.RandomBase; import com.minecrafttas.tasmod.networking.TASmodBufferBuilder; import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; import com.minecrafttas.tasmod.virtual.VirtualKeybindings; @@ -49,7 +49,7 @@ public enum TASmodKeybinds implements KeybindID { }), TEST1("Various Testing", "TASmod", Keyboard.KEY_F12, () -> { TASmod.getServerInstance().getEntityWorld().loadedEntityList.forEach(entity -> { - KTRNGRandom rand = (KTRNGRandom) entity.rand; + RandomBase rand = (RandomBase) entity.rand; rand.setSeed(0); }); }, VirtualKeybindings::isKeyDown), From 442bebdcee13e5425792b9632754300d3a972133 Mon Sep 17 00:00:00 2001 From: Scribble Date: Fri, 12 Sep 2025 11:39:21 +0200 Subject: [PATCH 05/26] [KillTheRNG] Add global seed to savestate storage --- .../java/com/minecrafttas/tasmod/TASmod.java | 5 ++ .../tasmod/ktrng/GlobalRandomnessTimer.java | 5 ++ .../storage/builtin/KTRNGSeedStorage.java | 67 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index 41daeb4f..805a557e 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -33,6 +33,8 @@ import com.minecrafttas.tasmod.savestates.handlers.SavestateGuiHandlerServer; import com.minecrafttas.tasmod.savestates.handlers.SavestateResourcePackHandler; import com.minecrafttas.tasmod.savestates.storage.builtin.ClientMotionStorage; +import com.minecrafttas.tasmod.savestates.storage.builtin.KTRNGSeedStorage; +import com.minecrafttas.tasmod.savestates.storage.builtin.SavestateMotionStorage; import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; import com.minecrafttas.tasmod.ticksync.TickSyncServer; import com.minecrafttas.tasmod.util.LoggerMarkers; @@ -88,6 +90,8 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop public static GlobalRandomnessTimer globalRandomness; + public static KTRNGSeedStorage seedStorage = new KTRNGSeedStorage(); + @Override public void onInitialize() { @@ -202,6 +206,7 @@ public void onServerStop(MinecraftServer mcserver) { private void registerSavestateStorage() { TASmodAPIRegistry.SAVESTATE_STORAGE.register(motionStorage); + TASmodAPIRegistry.SAVESTATE_STORAGE.register(seedStorage); } public static MinecraftServer getServerInstance() { diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java index 48faff67..c298e7ec 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java @@ -22,4 +22,9 @@ public void onServerTick(MinecraftServer server) { public long getCurrentSeed() { return currentSeed; } + + public void setSeed(long newSeed) { + globalRandomness.setSeed(newSeed); + currentSeed = newSeed; + } } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java new file mode 100644 index 00000000..99640cae --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -0,0 +1,67 @@ +package com.minecrafttas.tasmod.savestates.storage.builtin; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.savestates.SavestateHandlerServer; +import com.minecrafttas.tasmod.savestates.exceptions.LoadstateException; +import com.minecrafttas.tasmod.savestates.exceptions.SavestateException; +import com.minecrafttas.tasmod.savestates.storage.AbstractExtendStorage; + +import net.minecraft.server.MinecraftServer; + +public class KTRNGSeedStorage extends AbstractExtendStorage { + + private static final Path fileName = Paths.get("globalSeed.json"); + private final Gson json = new GsonBuilder().setPrettyPrinting().create(); + + @Override + public void onServerSavestate(MinecraftServer server, int index, Path target, Path current) { + long currentSeed = TASmod.globalRandomness.getCurrentSeed(); + JsonObject seedObject = new JsonObject(); + seedObject.addProperty("globalSeed", currentSeed); + saveJson(current, seedObject); + } + + private void saveJson(Path current, JsonObject data) { + Path saveFile = current.resolve(SavestateHandlerServer.storageDir).resolve(fileName); + + String out = json.toJson(data); + + try { + Files.write(saveFile, out.getBytes()); + } catch (IOException e) { + throw new SavestateException(e, "Could not write to the file system"); + } + } + + @Override + public void onServerLoadstate(MinecraftServer server, int index, Path target, Path current) { + JsonObject seedObject = loadJson(target); + if (!seedObject.has("globalSeed")) + return; + long newSeed = seedObject.get("globalSeed").getAsLong(); + TASmod.globalRandomness.setSeed(newSeed); + } + + private JsonObject loadJson(Path target) { + Path saveFile = target.resolve(SavestateHandlerServer.storageDir).resolve(fileName); + + if (!Files.exists(saveFile)) + return new JsonObject(); + + String in; + try { + in = new String(Files.readAllBytes(saveFile)); + } catch (IOException e) { + throw new LoadstateException(e, "Could not read from the file system"); + } + return json.fromJson(in, JsonObject.class); + } +} From 67b7f0c31c55bff554a575fa509ea6a7e564e538 Mon Sep 17 00:00:00 2001 From: Scribble Date: Sat, 13 Sep 2025 19:40:34 +0200 Subject: [PATCH 06/26] Update KTRNGSeedStorage to new format --- .../storage/builtin/KTRNGSeedStorage.java | 61 ++++--------------- 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index 99640cae..709563d7 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -1,67 +1,32 @@ package com.minecrafttas.tasmod.savestates.storage.builtin; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.savestates.SavestateHandlerServer; -import com.minecrafttas.tasmod.savestates.exceptions.LoadstateException; -import com.minecrafttas.tasmod.savestates.exceptions.SavestateException; -import com.minecrafttas.tasmod.savestates.storage.AbstractExtendStorage; +import com.minecrafttas.tasmod.savestates.storage.SavestateStorageExtensionBase; import net.minecraft.server.MinecraftServer; -public class KTRNGSeedStorage extends AbstractExtendStorage { +public class KTRNGSeedStorage extends SavestateStorageExtensionBase { - private static final Path fileName = Paths.get("globalSeed.json"); - private final Gson json = new GsonBuilder().setPrettyPrinting().create(); + public KTRNGSeedStorage() { + super("killtherngSeeds.json"); + } @Override - public void onServerSavestate(MinecraftServer server, int index, Path target, Path current) { + public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { long currentSeed = TASmod.globalRandomness.getCurrentSeed(); - JsonObject seedObject = new JsonObject(); - seedObject.addProperty("globalSeed", currentSeed); - saveJson(current, seedObject); - } - - private void saveJson(Path current, JsonObject data) { - Path saveFile = current.resolve(SavestateHandlerServer.storageDir).resolve(fileName); - - String out = json.toJson(data); - - try { - Files.write(saveFile, out.getBytes()); - } catch (IOException e) { - throw new SavestateException(e, "Could not write to the file system"); - } + dataToSave.addProperty("globalSeed", currentSeed); + return dataToSave; } @Override - public void onServerLoadstate(MinecraftServer server, int index, Path target, Path current) { - JsonObject seedObject = loadJson(target); - if (!seedObject.has("globalSeed")) - return; - long newSeed = seedObject.get("globalSeed").getAsLong(); + public void onLoadstate(MinecraftServer server, JsonObject loadedData) { + long newSeed = loadedData.get("globalSeed").getAsLong(); TASmod.globalRandomness.setSeed(newSeed); } - private JsonObject loadJson(Path target) { - Path saveFile = target.resolve(SavestateHandlerServer.storageDir).resolve(fileName); - - if (!Files.exists(saveFile)) - return new JsonObject(); - - String in; - try { - in = new String(Files.readAllBytes(saveFile)); - } catch (IOException e) { - throw new LoadstateException(e, "Could not read from the file system"); - } - return json.fromJson(in, JsonObject.class); + @Override + public String getExtensionName() { + return "KTRNGSeedStorage"; } } From ec1b962fdeff2d1dde175d22d33a0569c2a5202b Mon Sep 17 00:00:00 2001 From: Scribble Date: Sat, 13 Sep 2025 20:49:53 +0200 Subject: [PATCH 07/26] [Events] Add ServerStart Event This event is fired before ServerInit when worlds are alredy loaded --- .../minecrafttas/mctcommon/events/EventServer.java | 13 +++++++++++++ .../mctcommon/mixin/MixinMinecraftServer.java | 6 ++++++ src/main/java/com/minecrafttas/tasmod/TASmod.java | 14 ++++++++------ .../tasmod/registries/TASmodAPIRegistry.java | 5 ++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/minecrafttas/mctcommon/events/EventServer.java b/src/main/java/com/minecrafttas/mctcommon/events/EventServer.java index ea26c691..6973b2ab 100644 --- a/src/main/java/com/minecrafttas/mctcommon/events/EventServer.java +++ b/src/main/java/com/minecrafttas/mctcommon/events/EventServer.java @@ -13,6 +13,19 @@ */ public interface EventServer { + /** + * Fired, just before the server initialised, for both integrated and dedicated server. + */ + @FunctionalInterface + public static interface EventServerStart extends EventBase { + + /** + * Fired, when the server is initialised, for both integrated and dedicated server. + * @param server The server + */ + public void onServerStart(MinecraftServer server); + } + /** * Fired, when the server is initialised, for both integrated and dedicated server. */ diff --git a/src/main/java/com/minecrafttas/mctcommon/mixin/MixinMinecraftServer.java b/src/main/java/com/minecrafttas/mctcommon/mixin/MixinMinecraftServer.java index 4ea7d14f..b921efc9 100644 --- a/src/main/java/com/minecrafttas/mctcommon/mixin/MixinMinecraftServer.java +++ b/src/main/java/com/minecrafttas/mctcommon/mixin/MixinMinecraftServer.java @@ -9,6 +9,7 @@ import com.minecrafttas.mctcommon.events.EventListenerRegistry; import com.minecrafttas.mctcommon.events.EventServer.EventServerGameLoop; import com.minecrafttas.mctcommon.events.EventServer.EventServerInit; +import com.minecrafttas.mctcommon.events.EventServer.EventServerStart; import com.minecrafttas.mctcommon.events.EventServer.EventServerStop; import com.minecrafttas.mctcommon.events.EventServer.EventServerTick; @@ -17,6 +18,11 @@ @Mixin(MinecraftServer.class) public class MixinMinecraftServer { + @Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z")) + public void inject_initStart(CallbackInfo ci) { + EventListenerRegistry.fireEvent(EventServerStart.class, (MinecraftServer) (Object) this); + } + @Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z", shift = Shift.AFTER)) public void inject_init(CallbackInfo ci) { EventListenerRegistry.fireEvent(EventServerInit.class, (MinecraftServer) (Object) this); diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index 805a557e..53a386de 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -8,6 +8,7 @@ import com.minecrafttas.mctcommon.CommandRegistry; import com.minecrafttas.mctcommon.events.EventListenerRegistry; import com.minecrafttas.mctcommon.events.EventServer.EventServerInit; +import com.minecrafttas.mctcommon.events.EventServer.EventServerStart; import com.minecrafttas.mctcommon.events.EventServer.EventServerStop; import com.minecrafttas.mctcommon.networking.PacketHandlerRegistry; import com.minecrafttas.mctcommon.networking.Server; @@ -34,7 +35,6 @@ import com.minecrafttas.tasmod.savestates.handlers.SavestateResourcePackHandler; import com.minecrafttas.tasmod.savestates.storage.builtin.ClientMotionStorage; import com.minecrafttas.tasmod.savestates.storage.builtin.KTRNGSeedStorage; -import com.minecrafttas.tasmod.savestates.storage.builtin.SavestateMotionStorage; import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer; import com.minecrafttas.tasmod.ticksync.TickSyncServer; import com.minecrafttas.tasmod.util.LoggerMarkers; @@ -51,7 +51,7 @@ * * @author Scribble */ -public class TASmod implements ModInitializer, EventServerInit, EventServerStop { +public class TASmod implements ModInitializer, EventServerStart, EventServerInit, EventServerStop { public static final Logger LOGGER = LogManager.getLogger("TASmod"); @@ -135,12 +135,17 @@ public void onInitialize() { EventListenerRegistry.register(resourcepackHandler); PacketHandlerRegistry.register(playUntil); EventListenerRegistry.register(playUntil); - EventListenerRegistry.register(TASmodAPIRegistry.SAVESTATE_STORAGE); registerSavestateStorage(); } + @Override + public void onServerStart(MinecraftServer server) { + globalRandomness = new GlobalRandomnessTimer(); + EventListenerRegistry.register(globalRandomness); + } + @Override public void onServerInit(MinecraftServer server) { LOGGER.info("Initializing server"); @@ -166,9 +171,6 @@ public void onServerInit(MinecraftServer server) { PacketHandlerRegistry.register(savestateHandlerServer.getPlayerHandler()); EventListenerRegistry.register(savestateHandlerServer.getSavestateTemporaryHandler()); - globalRandomness = new GlobalRandomnessTimer(); - EventListenerRegistry.register(globalRandomness); - if (!server.isDedicatedServer()) { TASmod.tickratechanger.ticksPerSecond = 0F; TASmod.tickratechanger.tickrateSaved = 20F; diff --git a/src/main/java/com/minecrafttas/tasmod/registries/TASmodAPIRegistry.java b/src/main/java/com/minecrafttas/tasmod/registries/TASmodAPIRegistry.java index 33816e55..23b27d45 100644 --- a/src/main/java/com/minecrafttas/tasmod/registries/TASmodAPIRegistry.java +++ b/src/main/java/com/minecrafttas/tasmod/registries/TASmodAPIRegistry.java @@ -20,6 +20,7 @@ public class TASmodAPIRegistry { * savestate/rerecord count and category. * *

Any custom class has to implement PlaybackMetadataExtension + *

Side: Client

*/ public static final PlaybackMetadataRegistry PLAYBACK_METADATA = new PlaybackMetadataRegistry(); @@ -28,7 +29,7 @@ public class TASmodAPIRegistry { * *

File commands give the opportunity to run commands on each recorded tick and each played back tick.
* File commands also have access to the TASfile so that data can be stored and read in/from the TASfile. - * + *

Side: Client

*/ public static final PlaybackFileCommandsRegistry PLAYBACK_FILE_COMMAND = new PlaybackFileCommandsRegistry(); @@ -39,6 +40,7 @@ public class TASmodAPIRegistry { * or extend an existing flavor (like {@link Beta1Flavor}) and overwrite parts of the methods. * *

The resulting flavor can be registered here and can be found as a saving option with /saveTAS + *

Side: Client

*/ public static final SerialiserFlavorRegistry SERIALISER_FLAVOR = new SerialiserFlavorRegistry(); @@ -47,6 +49,7 @@ public class TASmodAPIRegistry { * *

Create a new ClientCommand by extending {@link ClientCommandBase},
* then create a command like normal, as it extends from the vanilla {@link CommandBase} + *

Side: Client

*/ public static final ClientCommandRegistry CLIENT_COMMANDS = new ClientCommandRegistry(); From 9498114f014b244ca7c0874e7412c9dd58c2f622 Mon Sep 17 00:00:00 2001 From: Scribble Date: Sat, 25 Oct 2025 22:30:54 +0200 Subject: [PATCH 08/26] Bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2a656019..3bb92fdd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,5 +16,5 @@ mod_email=scribble@minecrafttas.com # TASmod properties group=com.minecrafttas artifact=TASmod-1.12.2 -version=Beta2.1 +version=Beta3 release=false From 408c02f1be21f1cd8483725a99a2e52306536641 Mon Sep 17 00:00:00 2001 From: Scribble Date: Mon, 3 Nov 2025 20:51:24 +0100 Subject: [PATCH 09/26] [Savestate] Fix gross workaround when applying motion - [Event] Add EventLoadstatePost --- .../tasmod/events/EventSavestate.java | 19 +++++++++- .../savestates/SavestateHandlerServer.java | 4 +- .../SavestatePlayerHandlerClient.java | 37 ------------------- .../SavestateResourcePackHandler.java | 4 +- .../SavestateStorageExtensionBase.java | 1 + .../SavestateStorageExtensionRegistry.java | 6 +-- .../storage/builtin/ClientMotionStorage.java | 7 ++-- 7 files changed, 29 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java b/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java index 51ac126b..0add8095 100644 --- a/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java +++ b/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java @@ -27,7 +27,7 @@ interface EventServerSavestate extends EventBase { * Fired when loading a savestate, before the savestate folder is copied */ @FunctionalInterface - interface EventServerLoadstate extends EventBase { + interface EventServerLoadstatePre extends EventBase { /** * Fired when loading a savestate, before the savestate folder is copied @@ -35,7 +35,22 @@ interface EventServerLoadstate extends EventBase { * @param server The server instance * @param paths The {@link SavestatePaths} object */ - public void onServerLoadstate(MinecraftServer server, SavestatePaths paths); + public void onServerLoadstatePre(MinecraftServer server, SavestatePaths paths); + } + + /** + * Fired when loading a savestate, after the savestate folder is copied + */ + @FunctionalInterface + interface EventServerLoadstatePost extends EventBase { + + /** + * Fired when loading a savestate, after the savestate folder is copied + * + * @param server The server instance + * @param paths The {@link SavestatePaths} object + */ + public void onServerLoadstatePost(MinecraftServer server, SavestatePaths paths); } /** diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java b/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java index 150b67d5..ea672e62 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java @@ -384,7 +384,7 @@ private void loadStateInner(SavestatePaths paths, SavestateCallback cb, Savestat Path sourcefolder = paths.getSourceFolder(); Path targetfolder = paths.getTargetFolder(); - EventListenerRegistry.fireEvent(EventSavestate.EventServerLoadstate.class, server, paths); + EventListenerRegistry.fireEvent(EventSavestate.EventServerLoadstatePre.class, server, paths); /* * Prevents loading an InputSavestate when loading index 0 (Index 0 is the @@ -445,6 +445,8 @@ private void loadStateInner(SavestatePaths paths, SavestateCallback cb, Savestat worldHandler.sendChunksToClient(); + EventListenerRegistry.fireEvent(EventSavestate.EventServerLoadstatePost.class, server, paths); + if (SavestateFlags.BLOCK_PAUSE_TICKRATE.isBlocked(flags)) { TASmod.tickratechanger.pauseGame(false); } else { diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestatePlayerHandlerClient.java b/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestatePlayerHandlerClient.java index 878ec01f..a1bc64b7 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestatePlayerHandlerClient.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestatePlayerHandlerClient.java @@ -36,45 +36,8 @@ public void loadPlayer(NBTTagCompound compound) { // Clear any accidental applied potion particles on the client ((AccessorEntityLivingBase) player).clearPotionEffects(); - /* - * TODO - * The following 20 lines are all one - * gross workaround for correctly applying the player motion - * to the client... - * - * The motion is applied - * to the player in a previous step and unfortunately - * player.readFromNBT(compound) overwrites the - * previously applied motion... - * - * So this workaround makes sure that the motion is not overwritten - * Fixing this, requires restructuring the steps for loadstating - * and since I plan to do this anyway at some point, I will - * leave this here and be done for today*/ - double x = player.motionX; - double y = player.motionY; - double z = player.motionZ; - - float rx = player.moveForward; - float ry = player.moveVertical; - float rz = player.moveStrafing; - - boolean sprinting = player.isSprinting(); - float jumpVector = player.jumpMovementFactor; - player.readFromNBT(compound); - player.motionX = x; - player.motionY = y; - player.motionZ = z; - - player.moveForward = rx; - player.moveVertical = ry; - player.moveStrafing = rz; - - player.setSprinting(sprinting); - player.jumpMovementFactor = jumpVector; - LOGGER.trace(LoggerMarkers.Savestate, "Setting client gamemode"); // #86 int gamemode = compound.getInteger("playerGameType"); diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateResourcePackHandler.java b/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateResourcePackHandler.java index dcd76051..54c23313 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateResourcePackHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateResourcePackHandler.java @@ -35,7 +35,7 @@ * * @author Scribble */ -public class SavestateResourcePackHandler implements EventSavestate.EventServerLoadstate, ServerPacketHandler, ClientPacketHandler { +public class SavestateResourcePackHandler implements EventSavestate.EventServerLoadstatePre, ServerPacketHandler, ClientPacketHandler { /** * The server future for waiting until the client is done unloading the RP @@ -48,7 +48,7 @@ public class SavestateResourcePackHandler implements EventSavestate.EventServerL public static CountDownLatch clientRPLatch; @Override - public void onServerLoadstate(MinecraftServer server, SavestatePaths paths) { + public void onServerLoadstatePre(MinecraftServer server, SavestatePaths paths) { if (server.getResourcePackUrl().isEmpty() || server.isDedicatedServer()) return; diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java index 1f911302..3e78574c 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java @@ -26,4 +26,5 @@ public SavestateStorageExtensionBase(String fileName) { public abstract JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave); public abstract void onLoadstate(MinecraftServer server, JsonObject loadedData); + } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java index 8ab26bec..be0e0176 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java @@ -8,7 +8,7 @@ import com.google.gson.JsonObject; import com.minecrafttas.mctcommon.registry.AbstractRegistry; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.events.EventSavestate.EventServerLoadstate; +import com.minecrafttas.tasmod.events.EventSavestate.EventServerLoadstatePost; import com.minecrafttas.tasmod.events.EventSavestate.EventServerSavestate; import com.minecrafttas.tasmod.savestates.SavestateIndexer; import com.minecrafttas.tasmod.savestates.SavestateIndexer.SavestatePaths; @@ -18,7 +18,7 @@ import net.minecraft.server.MinecraftServer; -public class SavestateStorageExtensionRegistry extends AbstractRegistry implements EventServerSavestate, EventServerLoadstate { +public class SavestateStorageExtensionRegistry extends AbstractRegistry implements EventServerSavestate, EventServerLoadstatePost { public SavestateStorageExtensionRegistry() { super("SAVESTATESTORAGE_REGISTRY", new LinkedHashMap<>()); @@ -48,7 +48,7 @@ public void onServerSavestate(MinecraftServer server, SavestatePaths paths) { } @Override - public void onServerLoadstate(MinecraftServer server, SavestatePaths paths) { + public void onServerLoadstatePost(MinecraftServer server, SavestatePaths paths) { Path storageDir = paths.getTargetFolder().resolve(SavestateIndexer.savestateDataDir); if (!Files.exists(storageDir)) { try { diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java index 26b7151b..142616c8 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java @@ -97,17 +97,16 @@ public void onLoadstate(MinecraftServer server, JsonObject loadedData) { EntityPlayerMP player; if (playerUUID.equals("singleplayer")) { String ownerName = server.getServerOwner(); - if (ownerName == null) { + if (ownerName == null) continue; - } + player = list.getPlayerByUsername(ownerName); } else { player = list.getPlayerByUUID(UUID.fromString(playerUUID)); } - if (player == null) { + if (player == null) continue; - } try { TASmod.server.sendTo(player, new TASmodBufferBuilder(SAVESTATE_SET_MOTION).writeMotionData(motionData)); From 98fed945944af8209247ba2004fc627037f8f21b Mon Sep 17 00:00:00 2001 From: Scribble Date: Mon, 3 Nov 2025 22:26:51 +0100 Subject: [PATCH 10/26] [KillTheRNG] Add entity randomness saving and loading --- .../com/minecrafttas/tasmod/gui/InfoHud.java | 18 ++++----- .../tasmod/ktrng/EntityRandomness.java | 6 ++- .../tasmod/ktrng/KTRNGEntityHandler.java | 38 +++++++++++++++++++ .../minecrafttas/tasmod/ktrng/RandomBase.java | 2 +- .../storage/builtin/KTRNGSeedStorage.java | 37 ++++++++++++++++++ 5 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGEntityHandler.java diff --git a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java index 0269a886..17a02bfa 100644 --- a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java +++ b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java @@ -297,15 +297,15 @@ public boolean checkInit() { y += 14; // if (TASmod.ktrngHandler.isLoaded()) { -// title = "ktrng_randomseed"; -// if (configuration.getProperty(title + "_x", "err").equals("err")) -// setDefaults(title, y); -// lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title -// + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { -// if (Minecraft.getMinecraft().currentScreen == this) -// return "KTRNG"; -// return "RandomSeed: " + TASmod.ktrngHandler.getGlobalSeedClient(); -// })); + title = "ktrng_randomseed"; + if (configuration.getProperty(title + "_x", "err").equals("err")) + setDefaults(title, y); + lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { + if (Minecraft.getMinecraft().currentScreen == this) + return "KTRNG"; + return "Global RandomSeed: " + TASmod.globalRandomness.getCurrentSeed(); + })); // } title = "facing"; diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java index a84cf77e..810fd15a 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java @@ -4,9 +4,13 @@ public class EntityRandomness extends RandomBase { - private static long entityCounter = 0L; + public static long entityCounter = 0L; public EntityRandomness() { super(TASmod.globalRandomness.getCurrentSeed() + (entityCounter++)); } + + public EntityRandomness(long seed) { + super(seed); + } } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGEntityHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGEntityHandler.java new file mode 100644 index 00000000..62da4da6 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGEntityHandler.java @@ -0,0 +1,38 @@ +package com.minecrafttas.tasmod.ktrng; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.entity.Entity; +import net.minecraft.world.WorldServer; + +public class KTRNGEntityHandler { + + public static Map getRandomnessList() { + Map out = new HashMap<>(); + WorldServer[] worlds = TASmod.getServerInstance().worlds; + for (WorldServer worldServer : worlds) { + for (Entity entity : worldServer.loadedEntityList) { + UUID entityUUID = entity.getUniqueID(); + EntityRandomness entityRandomness = (EntityRandomness) entity.rand; + out.put(entityUUID, entityRandomness); + } + } + return out; + } + + public static void setRandomnessList(Map randomnessList) { + WorldServer[] worlds = TASmod.getServerInstance().worlds; + for (WorldServer worldServer : worlds) { + for (Entity entity : worldServer.loadedEntityList) { + UUID uuid = entity.getUniqueID(); + EntityRandomness rand = randomnessList.get(uuid); + if (rand != null) + entity.rand = rand; + } + } + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 6e609100..0cfb223e 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -160,7 +160,7 @@ public static long distance(long seed, long seed2) { @Override public String toString() { - return name + ": " + enabled; + return Long.toString(getSeed()); } @Override diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index 709563d7..a0833f22 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -1,7 +1,15 @@ package com.minecrafttas.tasmod.savestates.storage.builtin; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; + +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.ktrng.EntityRandomness; +import com.minecrafttas.tasmod.ktrng.KTRNGEntityHandler; import com.minecrafttas.tasmod.savestates.storage.SavestateStorageExtensionBase; import net.minecraft.server.MinecraftServer; @@ -16,6 +24,20 @@ public KTRNGSeedStorage() { public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { long currentSeed = TASmod.globalRandomness.getCurrentSeed(); dataToSave.addProperty("globalSeed", currentSeed); + + JsonObject entityRandomDataJson = new JsonObject(); + entityRandomDataJson.addProperty("entityCount", EntityRandomness.entityCounter); + + JsonObject entityRandomListJson = new JsonObject(); + Map randomList = KTRNGEntityHandler.getRandomnessList(); + for (Entry entry : randomList.entrySet()) { + entityRandomListJson.addProperty(entry.getKey().toString(), entry.getValue().getSeed()); + } + + entityRandomDataJson.add("entityList", entityRandomListJson); + + dataToSave.add("entityRandom", entityRandomDataJson); + return dataToSave; } @@ -23,6 +45,21 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { public void onLoadstate(MinecraftServer server, JsonObject loadedData) { long newSeed = loadedData.get("globalSeed").getAsLong(); TASmod.globalRandomness.setSeed(newSeed); + + JsonObject entityRandomDataJson = loadedData.get("entityRandom").getAsJsonObject(); + EntityRandomness.entityCounter = entityRandomDataJson.get("entityCount").getAsLong(); + + JsonObject entityRandomListJson = entityRandomDataJson.get("entityList").getAsJsonObject(); + + Map randomList = new HashMap<>(); + for (Entry entry : entityRandomListJson.entrySet()) { + UUID uuid = UUID.fromString(entry.getKey().toString()); + EntityRandomness entityRandomness = new EntityRandomness(entry.getValue().getAsLong()); + + randomList.put(uuid, entityRandomness); + } + + KTRNGEntityHandler.setRandomnessList(randomList); } @Override From cb31db601c2c715f4707664f370ea20433930928 Mon Sep 17 00:00:00 2001 From: Scribble Date: Sat, 8 Nov 2025 21:52:57 +0100 Subject: [PATCH 11/26] [KillTheRNG] Add world randomness saving and loading --- .../com/minecrafttas/tasmod/gui/InfoHud.java | 26 ++++++++++++- .../tasmod/ktrng/KTRNGWorldHandler.java | 38 +++++++++++++++++++ .../tasmod/ktrng/WorldRandomness.java | 14 +++++++ .../killtherng/MixinRenderLivingBase.java | 2 + .../tasmod/mixin/killtherng/MixinWorld.java | 20 ++++++++++ .../storage/builtin/KTRNGSeedStorage.java | 21 ++++++++++ src/main/resources/tasmod.accesswidener | 3 +- src/main/resources/tasmod.mixin.json | 3 +- 8 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java diff --git a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java index 17a02bfa..4d28d9c3 100644 --- a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java +++ b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java @@ -18,6 +18,8 @@ import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.TASmodClient; import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar; +import com.minecrafttas.tasmod.ktrng.EntityRandomness; +import com.minecrafttas.tasmod.ktrng.KTRNGWorldHandler; import com.minecrafttas.tasmod.playback.PlaybackControllerClient; import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension; @@ -296,7 +298,6 @@ public boolean checkInit() { y += 14; -// if (TASmod.ktrngHandler.isLoaded()) { title = "ktrng_randomseed"; if (configuration.getProperty(title + "_x", "err").equals("err")) setDefaults(title, y); @@ -306,7 +307,28 @@ public boolean checkInit() { return "KTRNG"; return "Global RandomSeed: " + TASmod.globalRandomness.getCurrentSeed(); })); -// } + + y += 14; + title = "ktrng_entitycount"; + if (configuration.getProperty(title + "_x", "err").equals("err")) + setDefaults(title, y); + lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { + if (Minecraft.getMinecraft().currentScreen == this) + return "EntityCount"; + return "EntityCount: " + EntityRandomness.entityCounter; + })); + + y += 14; + title = "ktrng_worldseed"; + if (configuration.getProperty(title + "_x", "err").equals("err")) + setDefaults(title, y); + lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { + if (Minecraft.getMinecraft().currentScreen == this) + return "WorldRNG"; + return "WorldRNG: " + KTRNGWorldHandler.getWorldRandom(); + })); title = "facing"; y += 14; diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java new file mode 100644 index 00000000..afc65b57 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java @@ -0,0 +1,38 @@ +package com.minecrafttas.tasmod.ktrng; + +import java.util.HashMap; +import java.util.Map; + +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.world.WorldServer; + +public class KTRNGWorldHandler { + + public static Map getWorldRandomnessMap() { + Map out = new HashMap<>(); + WorldServer[] worlds = TASmod.getServerInstance().worlds; + int id = 0; + for (WorldServer worldServer : worlds) { + WorldRandomness worldRandomness = (WorldRandomness) worldServer.rand; + out.put(id, worldRandomness); + id++; + } + return out; + } + + public static void setWorldRandomnessMap(Map randomnessList) { + WorldServer[] worlds = TASmod.getServerInstance().worlds; + int id = 0; + for (WorldServer worldServer : worlds) { + WorldRandomness worldRandomness = randomnessList.get(id); + if (worldRandomness != null) + worldServer.rand = worldRandomness; + id++; + } + } + + public static String getWorldRandom() { + return Long.toString(((WorldRandomness) TASmod.getServerInstance().worlds[0].rand).getSeed()); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java new file mode 100644 index 00000000..ee4316f0 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java @@ -0,0 +1,14 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.tasmod.TASmod; + +public class WorldRandomness extends RandomBase { + + public WorldRandomness(long seed) { + super(seed); + } + + public WorldRandomness() { + super(TASmod.globalRandomness.getCurrentSeed()); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java index 49b07a4f..8c81d1a8 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java @@ -31,6 +31,8 @@ protected MixinRenderLivingBase(RenderManager renderManager) { @Inject(method = "renderName", at = @At(value = "HEAD")) public void inject_renderName(EntityLivingBase entity, double d, double e, double f, CallbackInfo ci) { Entity serverEntity = TASmod.getServerInstance().getEntityFromUuid(entity.getUniqueID()); + if (serverEntity == null) + return; RandomBase random = (RandomBase) serverEntity.rand; long seed = random.getSeed(); long distance = -random.distance(random.getInitialSeed()); diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java new file mode 100644 index 00000000..8a710c49 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java @@ -0,0 +1,20 @@ +package com.minecrafttas.tasmod.mixin.killtherng; + +import java.util.Random; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.minecrafttas.tasmod.ktrng.WorldRandomness; + +import net.minecraft.world.World; + +@Mixin(World.class) +public class MixinWorld { + + @ModifyExpressionValue(method = "", at = @At(value = "NEW", target = "Ljava/util/Random;")) + public Random modify_worldRandom(Random original) { + return new WorldRandomness(); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index a0833f22..2ef352b5 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -10,6 +10,8 @@ import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.ktrng.EntityRandomness; import com.minecrafttas.tasmod.ktrng.KTRNGEntityHandler; +import com.minecrafttas.tasmod.ktrng.KTRNGWorldHandler; +import com.minecrafttas.tasmod.ktrng.WorldRandomness; import com.minecrafttas.tasmod.savestates.storage.SavestateStorageExtensionBase; import net.minecraft.server.MinecraftServer; @@ -38,6 +40,14 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { dataToSave.add("entityRandom", entityRandomDataJson); + JsonObject worldRandomDataJson = new JsonObject(); + Map worldRandom = KTRNGWorldHandler.getWorldRandomnessMap(); + for (Entry entry : worldRandom.entrySet()) { + worldRandomDataJson.addProperty(entry.getKey().toString(), entry.getValue().getSeed()); + } + + dataToSave.add("worldRandom", worldRandomDataJson); + return dataToSave; } @@ -60,6 +70,17 @@ public void onLoadstate(MinecraftServer server, JsonObject loadedData) { } KTRNGEntityHandler.setRandomnessList(randomList); + + JsonObject worldRandomListJson = loadedData.get("worldRandom").getAsJsonObject(); + + Map worldList = new HashMap<>(); + for (Entry entry : worldRandomListJson.entrySet()) { + int id = Integer.parseInt(entry.getKey()); + WorldRandomness worldRandomness = new WorldRandomness(entry.getValue().getAsLong()); + + worldList.put(id, worldRandomness); + } + KTRNGWorldHandler.setWorldRandomnessMap(worldList); } @Override diff --git a/src/main/resources/tasmod.accesswidener b/src/main/resources/tasmod.accesswidener index 7d539c92..7766c35b 100644 --- a/src/main/resources/tasmod.accesswidener +++ b/src/main/resources/tasmod.accesswidener @@ -14,4 +14,5 @@ accessible method net/minecraft/world/storage/SaveHandler setSessionLock ()V accessible field net/minecraft/client/settings/KeyBinding CATEGORY_ORDER Ljava/util/Map; #KillTheRNG -accessible field net/minecraft/entity/Entity rand Ljava/util/Random; \ No newline at end of file +accessible field net/minecraft/entity/Entity rand Ljava/util/Random; +mutable field net/minecraft/world/World rand Ljava/util/Random; \ No newline at end of file diff --git a/src/main/resources/tasmod.mixin.json b/src/main/resources/tasmod.mixin.json index f648916f..f7c7ec7b 100644 --- a/src/main/resources/tasmod.mixin.json +++ b/src/main/resources/tasmod.mixin.json @@ -23,7 +23,8 @@ // Fixing forge and vanilla stuff "fixes.MixinDragonFightManager", - "killtherng.MixinEntity" + "killtherng.MixinEntity", + "killtherng.MixinWorld" ], "client": [ From 9666ac80cf30454050a0c87bcaf3b42b6c727628 Mon Sep 17 00:00:00 2001 From: Scribble Date: Mon, 10 Nov 2025 19:46:23 +0100 Subject: [PATCH 12/26] [KillTheRNG] Add RNG logging --- .../com/minecrafttas/tasmod/ktrng/RandomBase.java | 14 +++++++++++++- .../minecrafttas/tasmod/ktrng/WorldRandomness.java | 5 +++++ .../minecrafttas/tasmod/util/LoggerMarkers.java | 2 ++ src/main/resources/log4j.xml | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 0cfb223e..7242c5d0 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -2,6 +2,9 @@ import java.util.Random; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.util.LoggerMarkers; + import kaptainwutax.seedutils.lcg.LCG; import kaptainwutax.seedutils.rand.JRand; @@ -174,7 +177,16 @@ public boolean equals(Object obj) { } public void fireEvent(long seed, String value) { - // TODO Implement + StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3]; + String methodName = stackTraceElement.getMethodName(); + String[] classNames = stackTraceElement.getClassName().split("\\."); + String className = classNames[classNames.length - 1]; + if (methodName.equals("showBarrierParticles")) + return; + String out = className + "." + methodName + + (stackTraceElement.isNativeMethod() ? "(Native Method)" : (stackTraceElement.getFileName() != null && stackTraceElement.getLineNumber() >= 0 ? "(" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + + ")" : (stackTraceElement.getFileName() != null ? "(" + stackTraceElement.getFileName() + ")" : "(Unknown Source)"))); + TASmod.LOGGER.debug(LoggerMarkers.KillTheRNG, "{}\t{}\t{}", seed, value, out); } public long getInitialSeed() { diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java index ee4316f0..eca1ea45 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java @@ -11,4 +11,9 @@ public WorldRandomness(long seed) { public WorldRandomness() { super(TASmod.globalRandomness.getCurrentSeed()); } + + @Override + public void fireEvent(long seed, String value) { +// super.fireEvent(seed, value); + } } diff --git a/src/main/java/com/minecrafttas/tasmod/util/LoggerMarkers.java b/src/main/java/com/minecrafttas/tasmod/util/LoggerMarkers.java index 1d2951ed..1a08fe30 100644 --- a/src/main/java/com/minecrafttas/tasmod/util/LoggerMarkers.java +++ b/src/main/java/com/minecrafttas/tasmod/util/LoggerMarkers.java @@ -47,6 +47,8 @@ public class LoggerMarkers implements EventDrawHotbarAlways { public static final Marker Mouse = MarkerManager.getMarker("Mouse"); + public static final Marker KillTheRNG = MarkerManager.getMarker("KillTheRNG"); + @Override public void onDrawHotbarAlways() { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml index 88fd9007..d2826b99 100644 --- a/src/main/resources/log4j.xml +++ b/src/main/resources/log4j.xml @@ -15,6 +15,8 @@ onMatch="${sys:tasmod.marker.keyboard:-DENY}" onMismatch="NEUTRAL" /> + From e9f9351d98ae0eb230a56040867b0e0bbec8897a Mon Sep 17 00:00:00 2001 From: Scribble Date: Wed, 12 Nov 2025 21:32:33 +0100 Subject: [PATCH 13/26] [KillTheRNG] Only redirect server EntityRNG, add initial seed to EntityDisplay --- .../tasmod/ktrng/GlobalRandomnessTimer.java | 2 +- .../ktrng/GlobalRandomnessTimerClient.java | 38 +++++++++++++++++++ .../minecrafttas/tasmod/ktrng/RandomBase.java | 4 ++ .../tasmod/mixin/killtherng/MixinEntity.java | 9 ++++- .../killtherng/MixinRenderLivingBase.java | 1 + 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java index c298e7ec..ccfc3911 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java @@ -6,7 +6,7 @@ public class GlobalRandomnessTimer implements EventServer.EventServerTick { - private RandomBase globalRandomness; + private final RandomBase globalRandomness; private long currentSeed = 0L; diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java new file mode 100644 index 00000000..ea94251c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java @@ -0,0 +1,38 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.mctcommon.events.EventClient; + +import net.minecraft.client.Minecraft; + +public class GlobalRandomnessTimerClient implements EventClient.EventClientTick { + + private final RandomBase globalRandomness; + private final RandomBase uuidRandomness; + + private long currentSeed = 0L; + + public GlobalRandomnessTimerClient() { + globalRandomness = new RandomBase(0L); + uuidRandomness = new RandomBase(0L); + } + + @Override + public void onClientTick(Minecraft mc) { + currentSeed = globalRandomness.nextLong(); + uuidRandomness.setSeed(currentSeed); + } + + public long getCurrentSeed() { + return currentSeed; + } + + public RandomBase getUUIDRandom() { + return uuidRandomness; + } + + public void setSeed(long newSeed) { + globalRandomness.setSeed(newSeed); + currentSeed = newSeed; + } + +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 7242c5d0..5972a36c 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -20,6 +20,10 @@ public class RandomBase extends Random { private long initialSeed; + public RandomBase() { + super(); + } + public RandomBase(long seed) { super(seed); this.initialSeed = seed; diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java index 89b3f9ce..a0d5c930 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java @@ -9,12 +9,17 @@ import com.minecrafttas.tasmod.ktrng.EntityRandomness; import net.minecraft.entity.Entity; +import net.minecraft.world.World; @Mixin(Entity.class) public class MixinEntity { @ModifyExpressionValue(method = "", at = @At(value = "NEW", target = "Ljava/util/Random;")) - public Random modify_entityRandom(Random original) { - return new EntityRandomness(); + public Random modify_entityRandom(Random original, World world) { + if (!world.isRemote) { + return new EntityRandomness(); + } else { + return new EntityRandomness(0L); + } } } diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java index 8c81d1a8..f7953eb3 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinRenderLivingBase.java @@ -37,6 +37,7 @@ public void inject_renderName(EntityLivingBase entity, double d, double e, doubl long seed = random.getSeed(); long distance = -random.distance(random.getInitialSeed()); GlStateManager.alphaFunc(516, 0.1F); + this.renderEntityName(entity, d, e + 0.69D, f, Long.toString(random.getInitialSeed()), 64); this.renderEntityName(entity, d, e + 0.46D, f, Long.toString(seed), 64); this.renderEntityName(entity, d, e + 0.23D, f, Long.toString(distance), 64); } From 2e56e6f9e3c8fae013353d1c93f9fec68add72b2 Mon Sep 17 00:00:00 2001 From: Scribble Date: Wed, 12 Nov 2025 21:32:33 +0100 Subject: [PATCH 14/26] [Savestates] Add more loadstate events to SavestateStorage - [KillTheRNG] Remove entitycount --- .../tasmod/events/EventSavestate.java | 2 +- .../com/minecrafttas/tasmod/gui/InfoHud.java | 21 ++++++----- .../tasmod/ktrng/EntityRandomness.java | 4 +-- .../tasmod/mixin/killtherng/MixinEntity.java | 8 +++++ .../savestates/SavestateHandlerServer.java | 2 +- .../SavestateStorageExtensionBase.java | 8 ++++- .../SavestateStorageExtensionRegistry.java | 36 +++++++++++++++---- .../storage/builtin/ClientMotionStorage.java | 2 +- .../storage/builtin/KTRNGSeedStorage.java | 4 +-- 9 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java b/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java index 0add8095..dda3601f 100644 --- a/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java +++ b/src/main/java/com/minecrafttas/tasmod/events/EventSavestate.java @@ -62,7 +62,7 @@ interface EventServerCompleteLoadstate extends EventBase { /** * Fired one tick after a loadstate was carried out */ - public void onServerLoadstateComplete(); + public void onServerLoadstateComplete(MinecraftServer server, SavestatePaths paths); } /** diff --git a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java index 4d28d9c3..37758dd3 100644 --- a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java +++ b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java @@ -18,7 +18,6 @@ import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.TASmodClient; import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar; -import com.minecrafttas.tasmod.ktrng.EntityRandomness; import com.minecrafttas.tasmod.ktrng.KTRNGWorldHandler; import com.minecrafttas.tasmod.playback.PlaybackControllerClient; import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; @@ -308,16 +307,16 @@ public boolean checkInit() { return "Global RandomSeed: " + TASmod.globalRandomness.getCurrentSeed(); })); - y += 14; - title = "ktrng_entitycount"; - if (configuration.getProperty(title + "_x", "err").equals("err")) - setDefaults(title, y); - lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title - + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { - if (Minecraft.getMinecraft().currentScreen == this) - return "EntityCount"; - return "EntityCount: " + EntityRandomness.entityCounter; - })); +// y += 14; +// title = "ktrng_entitycount"; +// if (configuration.getProperty(title + "_x", "err").equals("err")) +// setDefaults(title, y); +// lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title +// + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { +// if (Minecraft.getMinecraft().currentScreen == this) +// return "EntityCount"; +// return "EntityCount: " + EntityRandomness.entityCounter; +// })); y += 14; title = "ktrng_worldseed"; diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java index 810fd15a..f920d916 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java @@ -4,10 +4,8 @@ public class EntityRandomness extends RandomBase { - public static long entityCounter = 0L; - public EntityRandomness() { - super(TASmod.globalRandomness.getCurrentSeed() + (entityCounter++)); + super(TASmod.globalRandomness.getCurrentSeed()); } public EntityRandomness(long seed) { diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java index a0d5c930..3bef0312 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java @@ -1,11 +1,14 @@ package com.minecrafttas.tasmod.mixin.killtherng; import java.util.Random; +import java.util.UUID; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.minecrafttas.tasmod.ktrng.EntityRandomness; import net.minecraft.entity.Entity; @@ -22,4 +25,9 @@ public Random modify_entityRandom(Random original, World world) { return new EntityRandomness(0L); } } + + @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;getRandomUUID(Ljava/util/Random;)Ljava/util/UUID;")) + private UUID wrap_getRandomUUID(Random rand, Operation original) { + return original.call(new Random()); + } } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java b/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java index ea672e62..ea4d0745 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java @@ -469,7 +469,7 @@ private void loadStateInner(SavestatePaths paths, SavestateCallback cb, Savestat * Rn it's not a problem, but this should be looked at... */ TASmod.tickSchedulerServer.add(() -> { - EventListenerRegistry.fireEvent(EventSavestate.EventServerCompleteLoadstate.class); + EventListenerRegistry.fireEvent(EventSavestate.EventServerCompleteLoadstate.class, server, paths); onLoadstateComplete(); }); } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java index 3e78574c..3e1b5b3a 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionBase.java @@ -25,6 +25,12 @@ public SavestateStorageExtensionBase(String fileName) { public abstract JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave); - public abstract void onLoadstate(MinecraftServer server, JsonObject loadedData); + public void onLoadstatePre(MinecraftServer server, JsonObject loadedData) { + } + + public void onLoadstatePost(MinecraftServer server, JsonObject loadedData) { + } + public void onLoadstateComplete(MinecraftServer server, JsonObject loadedData) { + } } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java index be0e0176..086e74cd 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java @@ -3,13 +3,14 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Map; import com.google.gson.JsonObject; import com.minecrafttas.mctcommon.registry.AbstractRegistry; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.events.EventSavestate.EventServerLoadstatePost; -import com.minecrafttas.tasmod.events.EventSavestate.EventServerSavestate; +import com.minecrafttas.tasmod.events.EventSavestate; import com.minecrafttas.tasmod.savestates.SavestateIndexer; import com.minecrafttas.tasmod.savestates.SavestateIndexer.SavestatePaths; import com.minecrafttas.tasmod.savestates.exceptions.LoadstateException; @@ -18,7 +19,9 @@ import net.minecraft.server.MinecraftServer; -public class SavestateStorageExtensionRegistry extends AbstractRegistry implements EventServerSavestate, EventServerLoadstatePost { +public class SavestateStorageExtensionRegistry extends AbstractRegistry implements EventSavestate.EventServerSavestate, EventSavestate.EventServerLoadstatePre, EventSavestate.EventServerLoadstatePost, EventSavestate.EventServerCompleteLoadstate { + + Map jsonMap = new HashMap<>(); public SavestateStorageExtensionRegistry() { super("SAVESTATESTORAGE_REGISTRY", new LinkedHashMap<>()); @@ -47,8 +50,8 @@ public void onServerSavestate(MinecraftServer server, SavestatePaths paths) { } } - @Override - public void onServerLoadstatePost(MinecraftServer server, SavestatePaths paths) { + private void load(SavestatePaths paths) { + jsonMap.clear(); Path storageDir = paths.getTargetFolder().resolve(SavestateIndexer.savestateDataDir); if (!Files.exists(storageDir)) { try { @@ -72,8 +75,29 @@ public void onServerLoadstatePost(MinecraftServer server, SavestatePaths paths) } catch (IOException e) { throw new LoadstateException(e, "Can't load %s in %s extension", storage.fileName, storage.getExtensionName()); } + jsonMap.put(storage, loadedData); + } + } + + @Override + public void onServerLoadstatePre(MinecraftServer server, SavestatePaths paths) { + load(paths); + for (SavestateStorageExtensionBase storage : REGISTRY.values()) { + storage.onLoadstatePre(server, jsonMap.get(storage)); + } + } - storage.onLoadstate(server, loadedData); + @Override + public void onServerLoadstatePost(MinecraftServer server, SavestatePaths paths) { + for (SavestateStorageExtensionBase storage : REGISTRY.values()) { + storage.onLoadstatePost(server, jsonMap.get(storage)); + } + } + + @Override + public void onServerLoadstateComplete(MinecraftServer server, SavestatePaths paths) { + for (SavestateStorageExtensionBase storage : REGISTRY.values()) { + storage.onLoadstateComplete(TASmod.getServerInstance(), jsonMap.get(storage)); } } } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java index 142616c8..81f89e55 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/ClientMotionStorage.java @@ -87,7 +87,7 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { } @Override - public void onLoadstate(MinecraftServer server, JsonObject loadedData) { + public void onLoadstatePost(MinecraftServer server, JsonObject loadedData) { PlayerList list = server.getPlayerList(); for (Entry motionDataJsonElement : loadedData.entrySet()) { diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index 2ef352b5..2ba78b01 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -28,7 +28,6 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { dataToSave.addProperty("globalSeed", currentSeed); JsonObject entityRandomDataJson = new JsonObject(); - entityRandomDataJson.addProperty("entityCount", EntityRandomness.entityCounter); JsonObject entityRandomListJson = new JsonObject(); Map randomList = KTRNGEntityHandler.getRandomnessList(); @@ -52,12 +51,11 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { } @Override - public void onLoadstate(MinecraftServer server, JsonObject loadedData) { + public void onLoadstateComplete(MinecraftServer server, JsonObject loadedData) { long newSeed = loadedData.get("globalSeed").getAsLong(); TASmod.globalRandomness.setSeed(newSeed); JsonObject entityRandomDataJson = loadedData.get("entityRandom").getAsJsonObject(); - EntityRandomness.entityCounter = entityRandomDataJson.get("entityCount").getAsLong(); JsonObject entityRandomListJson = entityRandomDataJson.get("entityList").getAsJsonObject(); From 3eea70be727fdef5bf8b02041893c566913d499e Mon Sep 17 00:00:00 2001 From: Scribble Date: Sun, 16 Nov 2025 15:19:10 +0100 Subject: [PATCH 15/26] [KillTheRNG] Fix GlobalRandomness not advancing correctly --- .../com/minecrafttas/tasmod/ktrng/EntityRandomness.java | 2 ++ .../minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java | 3 ++- .../com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java | 5 ++++- .../com/minecrafttas/tasmod/registries/TASmodKeybinds.java | 6 ------ 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java index f920d916..a5de00bf 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java @@ -4,6 +4,8 @@ public class EntityRandomness extends RandomBase { + public static long entityCount = 0; + public EntityRandomness() { super(TASmod.globalRandomness.getCurrentSeed()); } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java index ccfc3911..6d64417b 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java @@ -16,7 +16,8 @@ public GlobalRandomnessTimer() { @Override public void onServerTick(MinecraftServer server) { - currentSeed = globalRandomness.nextLong(); + globalRandomness.advance(); + currentSeed = globalRandomness.getSeed(); } public long getCurrentSeed() { diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java index afc65b57..3ba1e10b 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java @@ -33,6 +33,9 @@ public static void setWorldRandomnessMap(Map randomnes } public static String getWorldRandom() { - return Long.toString(((WorldRandomness) TASmod.getServerInstance().worlds[0].rand).getSeed()); + if (TASmod.getServerInstance().worlds[0] != null) + return Long.toString(((WorldRandomness) TASmod.getServerInstance().worlds[0].rand).getSeed()); + else + return ""; } } diff --git a/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java b/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java index c60347da..bbd88526 100644 --- a/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java +++ b/src/main/java/com/minecrafttas/tasmod/registries/TASmodKeybinds.java @@ -5,9 +5,7 @@ import com.minecrafttas.mctcommon.KeybindManager.IsKeyDownFunc; import com.minecrafttas.mctcommon.KeybindManager.Keybind; import com.minecrafttas.mctcommon.KeybindManager.KeybindID; -import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.TASmodClient; -import com.minecrafttas.tasmod.ktrng.RandomBase; import com.minecrafttas.tasmod.networking.TASmodBufferBuilder; import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; import com.minecrafttas.tasmod.virtual.VirtualKeybindings; @@ -48,10 +46,6 @@ public enum TASmodKeybinds implements KeybindID { TASmodClient.virtual.CAMERA_ANGLE.updateNextCameraAngle(0, 45); }), TEST1("Various Testing", "TASmod", Keyboard.KEY_F12, () -> { - TASmod.getServerInstance().getEntityWorld().loadedEntityList.forEach(entity -> { - RandomBase rand = (RandomBase) entity.rand; - rand.setSeed(0); - }); }, VirtualKeybindings::isKeyDown), TEST2("Various Testing2", "TASmod", Keyboard.KEY_F7, () -> { }, VirtualKeybindings::isKeyDown); From 7bd04fadc080b5b77c071334d424be19e2997729 Mon Sep 17 00:00:00 2001 From: Scribble Date: Wed, 19 Nov 2025 20:20:08 +0100 Subject: [PATCH 16/26] [KillTheRNG] Add world.updateLCG to randomness pool --- .../tasmod/ktrng/KTRNGWorldHandler.java | 23 +++++++++++ .../minecrafttas/tasmod/ktrng/RandomBase.java | 6 ++- .../tasmod/ktrng/WorldRandomness.java | 4 +- .../storage/builtin/KTRNGSeedStorage.java | 29 ++++++++++++-- src/main/resources/tasmod.accesswidener | 1 + src/test/java/tasmod/killtherng/RNGTest.java | 39 +++++++++++++++++++ 6 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 src/test/java/tasmod/killtherng/RNGTest.java diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java index 3ba1e10b..d1c66971 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java @@ -21,6 +21,18 @@ public static Map getWorldRandomnessMap() { return out; } + public static Map getWorldLCGMap() { + Map out = new HashMap<>(); + WorldServer[] worlds = TASmod.getServerInstance().worlds; + int id = 0; + for (WorldServer worldServer : worlds) { + int updateLCG = worldServer.updateLCG; + out.put(id, updateLCG); + id++; + } + return out; + } + public static void setWorldRandomnessMap(Map randomnessList) { WorldServer[] worlds = TASmod.getServerInstance().worlds; int id = 0; @@ -32,6 +44,17 @@ public static void setWorldRandomnessMap(Map randomnes } } + public static void setWorldLCGMap(Map lcgList) { + WorldServer[] worlds = TASmod.getServerInstance().worlds; + int id = 0; + for (WorldServer worldServer : worlds) { + Integer updateLCG = lcgList.get(id); + if (updateLCG != null) + worldServer.updateLCG = updateLCG; + id++; + } + } + public static String getWorldRandom() { if (TASmod.getServerInstance().worlds[0] != null) return Long.toString(((WorldRandomness) TASmod.getServerInstance().worlds[0].rand).getSeed()); diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 5972a36c..19f636db 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -181,7 +181,11 @@ public boolean equals(Object obj) { } public void fireEvent(long seed, String value) { - StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[3]; + fireEvent(seed, value, 3); + } + + public void fireEvent(long seed, String value, int stackTraceOffset) { + StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[stackTraceOffset]; String methodName = stackTraceElement.getMethodName(); String[] classNames = stackTraceElement.getClassName().split("\\."); String className = classNames[classNames.length - 1]; diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java index eca1ea45..858fed59 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java @@ -13,7 +13,7 @@ public WorldRandomness() { } @Override - public void fireEvent(long seed, String value) { -// super.fireEvent(seed, value); + public void fireEvent(long seed, String value, int offset) { + //super.fireEvent(seed, value, 5); } } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index 2ba78b01..0c0848b6 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -40,11 +40,23 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { dataToSave.add("entityRandom", entityRandomDataJson); JsonObject worldRandomDataJson = new JsonObject(); + + JsonObject worldListJson = new JsonObject(); Map worldRandom = KTRNGWorldHandler.getWorldRandomnessMap(); for (Entry entry : worldRandom.entrySet()) { - worldRandomDataJson.addProperty(entry.getKey().toString(), entry.getValue().getSeed()); + worldListJson.addProperty(entry.getKey().toString(), entry.getValue().getSeed()); } + worldRandomDataJson.add("worldList", worldListJson); + + JsonObject lcgListJson = new JsonObject(); + Map lcgMap = KTRNGWorldHandler.getWorldLCGMap(); + for (Entry entry : lcgMap.entrySet()) { + lcgListJson.addProperty(entry.getKey().toString(), entry.getValue()); + } + + worldRandomDataJson.add("lcgList", lcgListJson); + dataToSave.add("worldRandom", worldRandomDataJson); return dataToSave; @@ -69,15 +81,26 @@ public void onLoadstateComplete(MinecraftServer server, JsonObject loadedData) { KTRNGEntityHandler.setRandomnessList(randomList); - JsonObject worldRandomListJson = loadedData.get("worldRandom").getAsJsonObject(); + JsonObject worldRandomJson = loadedData.get("worldRandom").getAsJsonObject(); + JsonObject worldListJson = worldRandomJson.get("worldList").getAsJsonObject(); Map worldList = new HashMap<>(); - for (Entry entry : worldRandomListJson.entrySet()) { + for (Entry entry : worldListJson.entrySet()) { int id = Integer.parseInt(entry.getKey()); WorldRandomness worldRandomness = new WorldRandomness(entry.getValue().getAsLong()); worldList.put(id, worldRandomness); } + + JsonObject worldLCGList = worldRandomJson.get("lcgList").getAsJsonObject(); + Map lcgList = new HashMap<>(); + for (Entry entry : worldLCGList.entrySet()) { + int id = Integer.parseInt(entry.getKey()); + int lcg = entry.getValue().getAsInt(); + + lcgList.put(id, lcg); + } + KTRNGWorldHandler.setWorldRandomnessMap(worldList); } diff --git a/src/main/resources/tasmod.accesswidener b/src/main/resources/tasmod.accesswidener index 7766c35b..1f287702 100644 --- a/src/main/resources/tasmod.accesswidener +++ b/src/main/resources/tasmod.accesswidener @@ -15,4 +15,5 @@ accessible field net/minecraft/client/settings/KeyBinding CATEGORY_ORDER Ljava/u #KillTheRNG accessible field net/minecraft/entity/Entity rand Ljava/util/Random; +accessible field net/minecraft/world/World updateLCG I mutable field net/minecraft/world/World rand Ljava/util/Random; \ No newline at end of file diff --git a/src/test/java/tasmod/killtherng/RNGTest.java b/src/test/java/tasmod/killtherng/RNGTest.java new file mode 100644 index 00000000..b969345e --- /dev/null +++ b/src/test/java/tasmod/killtherng/RNGTest.java @@ -0,0 +1,39 @@ +package tasmod.killtherng; + +import com.minecrafttas.tasmod.ktrng.RandomBase; + +public class RNGTest { + + public static void main(String[] args) { + long[] longlist = new long[] { + //@formatter:off + 113621727298730L, + 161845404674820L + //@formatter:on + }; + + printDistance(longlist); + + longlist = new long[] { + //@formatter:off + 161845404674820L, + 107865211428631L, + 252587169991970L, + 223075662074294L, + 66246869218509L, + 81210955942352L, + 183553865074233L, + 11371681017552L + //@formatter:on + }; +// printDistance(longlist); + } + + private static void printDistance(long[] list) { + long prev = list[0]; + for (long l : list) { + System.out.println(RandomBase.distance(prev, l)); + } + System.out.println(""); + } +} From 7f87e615d5fdc56364c2bcb0a254caa98553071f Mon Sep 17 00:00:00 2001 From: Scribble Date: Wed, 19 Nov 2025 20:41:06 +0100 Subject: [PATCH 17/26] [KillTheRNG] Improve logging in RandomBase --- .../minecrafttas/tasmod/ktrng/RandomBase.java | 33 +++++++++++-------- .../tasmod/ktrng/WorldRandomness.java | 4 +-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 19f636db..8f2be415 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -29,13 +29,14 @@ public RandomBase(long seed) { this.initialSeed = seed; } + @Override public void setSeed(long seedIn) { - timesCalled = 0; - super.setSeed(seedIn ^ 0x5deece66dL); + setSeed(seedIn, true); } - public void setSeed(long seedIn, boolean shouldIncrease) { - timesCalled++; + public void setSeed(long seedIn, boolean shouldLog) { + if (shouldLog) + fireSetEvent("setSeed()", seedIn, "", 8); super.setSeed(seedIn ^ 0x5deece66dL); } @@ -76,7 +77,7 @@ public long nextLong() { timesCalled++; long seedstored = getSeed(); long value = super.nextLong(); - fireEvent(seedstored, Long.toString(value)); + fireGetEvent("nextLong()", seedstored, Long.toString(value)); return value; } @@ -85,7 +86,7 @@ public double nextDouble() { timesCalled++; long seedstored = getSeed(); double value = super.nextDouble(); - fireEvent(seedstored, Double.toString(value)); + fireGetEvent("nextDouble()", seedstored, Double.toString(value)); return value; } @@ -94,7 +95,7 @@ public boolean nextBoolean() { timesCalled++; long seedstored = getSeed(); boolean value = super.nextBoolean(); - fireEvent(seedstored, Boolean.toString(value)); + fireGetEvent("nextBoolean()", seedstored, Boolean.toString(value)); return value; } @@ -103,7 +104,7 @@ public int nextInt() { timesCalled++; long seedstored = getSeed(); int value = super.nextInt(); - fireEvent(seedstored, Integer.toString(value)); + fireGetEvent("nextInt()", seedstored, Integer.toString(value)); return value; } @@ -112,7 +113,7 @@ public int nextInt(int bound) { timesCalled++; long seedstored = getSeed(); int value = super.nextInt(bound); - fireEvent(seedstored, Integer.toString(value)); + fireGetEvent(String.format("nextInt(%s)", bound), seedstored, Integer.toString(value)); return value; } @@ -141,7 +142,7 @@ public void advance() { public void advance(long i) { JRand thing = JRand.ofInternalSeed(getSeed()); thing.advance(i); - setSeed(thing.getSeed()); + setSeed(thing.getSeed(), false); } public long getSeedAt(int steps) { @@ -180,11 +181,15 @@ public boolean equals(Object obj) { } } - public void fireEvent(long seed, String value) { - fireEvent(seed, value, 3); + public void fireSetEvent(String eventType, long seed, String value, int stackTraceOffset) { + fireEvent(eventType, seed, value, stackTraceOffset); + } + + public void fireGetEvent(String eventType, long seed, String value) { + //fireEvent(eventType, seed, value, 3); } - public void fireEvent(long seed, String value, int stackTraceOffset) { + public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[stackTraceOffset]; String methodName = stackTraceElement.getMethodName(); String[] classNames = stackTraceElement.getClassName().split("\\."); @@ -194,7 +199,7 @@ public void fireEvent(long seed, String value, int stackTraceOffset) { String out = className + "." + methodName + (stackTraceElement.isNativeMethod() ? "(Native Method)" : (stackTraceElement.getFileName() != null && stackTraceElement.getLineNumber() >= 0 ? "(" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + ")" : (stackTraceElement.getFileName() != null ? "(" + stackTraceElement.getFileName() + ")" : "(Unknown Source)"))); - TASmod.LOGGER.debug(LoggerMarkers.KillTheRNG, "{}\t{}\t{}", seed, value, out); + TASmod.LOGGER.debug(LoggerMarkers.KillTheRNG, "{} {}\t{}\t{}", eventType, seed, value, out); } public long getInitialSeed() { diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java index 858fed59..01a51b7c 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java @@ -13,7 +13,7 @@ public WorldRandomness() { } @Override - public void fireEvent(long seed, String value, int offset) { - //super.fireEvent(seed, value, 5); + public void fireEvent(String val, long seed, String value, int offset) { + //super.fireEvent(val, seed, value, 5); } } From b567d00b518b2baf56fd508876e270f7722e3115 Mon Sep 17 00:00:00 2001 From: Scribble Date: Thu, 27 Nov 2025 21:20:47 +0100 Subject: [PATCH 18/26] [Tickrate] Remove processing the server task queue in Tickrate 0 --- .../tasmod/mixin/MixinMinecraftServer.java | 25 +++++++++---------- .../handlers/SavestateTempHandler.java | 4 +-- .../storage/builtin/KTRNGSeedStorage.java | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java index 5a57d75d..09876ee0 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java @@ -13,7 +13,6 @@ import com.minecrafttas.mctcommon.events.EventListenerRegistry; import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.events.EventServer.EventServerTickPost; -import com.minecrafttas.tasmod.savestates.SavestateHandlerServer.SavestateState; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -110,18 +109,18 @@ public void redirectThreadSleep(long msToTick) { TASmod.gameLoopSchedulerServer.runAllTasks(); - boolean stopTaskQueue = TASmod.savestateHandlerServer != null && TASmod.savestateHandlerServer.getState() == SavestateState.LOADING; - if (!stopTaskQueue) { - synchronized (this.futureTaskQueue) { - while (!this.futureTaskQueue.isEmpty()) { - try { - ((FutureTask) this.futureTaskQueue.poll()).run(); - } catch (Throwable var9) { - var9.printStackTrace(); - } - } - } - } +// boolean stopTaskQueue = TASmod.savestateHandlerServer != null && TASmod.savestateHandlerServer.getState() == SavestateState.LOADING; +// if (!stopTaskQueue) { +// synchronized (this.futureTaskQueue) { +// while (!this.futureTaskQueue.isEmpty()) { +// try { +// ((FutureTask) this.futureTaskQueue.poll()).run(); +// } catch (Throwable var9) { +// var9.printStackTrace(); +// } +// } +// } +// } } @Environment(EnvType.SERVER) diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateTempHandler.java b/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateTempHandler.java index 619985e8..0474b760 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateTempHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateTempHandler.java @@ -29,7 +29,7 @@ * * @author Scribble */ -public class SavestateTempHandler implements EventControllerStateChange, EventRecordClear, EventSavestate.EventServerLoadstate { +public class SavestateTempHandler implements EventControllerStateChange, EventRecordClear, EventSavestate.EventServerLoadstatePre { private final Logger logger; private final SavestateHandlerServer handler; @@ -149,7 +149,7 @@ public void setNoSave(boolean noSave) { } @Override - public void onServerLoadstate(MinecraftServer server, SavestatePaths paths) { + public void onServerLoadstatePre(MinecraftServer server, SavestatePaths paths) { createState = false; } } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index 0c0848b6..b1ee3dd6 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -64,6 +64,7 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { @Override public void onLoadstateComplete(MinecraftServer server, JsonObject loadedData) { + TASmod.LOGGER.debug("Loading KTRNG seeds"); long newSeed = loadedData.get("globalSeed").getAsLong(); TASmod.globalRandomness.setSeed(newSeed); From 8046ff0bd18b3ae1b5ec3033a0cb39773f55a4f6 Mon Sep 17 00:00:00 2001 From: Scribble Date: Mon, 1 Dec 2025 21:57:35 +0100 Subject: [PATCH 19/26] [KillTheRNG] Started adding MathRandomness --- .../java/com/minecrafttas/tasmod/TASmod.java | 4 ++++ .../tasmod/ktrng/MathRandomness.java | 19 +++++++++++++++++ .../killtherng/mathrand/MixinEntityItem.java | 21 +++++++++++++++++++ .../mathrand/MixinEntityLivingBase.java | 19 +++++++++++++++++ .../storage/builtin/KTRNGSeedStorage.java | 4 ++++ src/main/resources/tasmod.mixin.json | 4 +++- 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index 53a386de..302f0860 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -26,6 +26,7 @@ import com.minecrafttas.tasmod.commands.CommandTickrate; import com.minecrafttas.tasmod.handlers.PlayUntilHandler; import com.minecrafttas.tasmod.ktrng.GlobalRandomnessTimer; +import com.minecrafttas.tasmod.ktrng.MathRandomness; import com.minecrafttas.tasmod.playback.PlaybackControllerServer; import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension; import com.minecrafttas.tasmod.registries.TASmodAPIRegistry; @@ -92,6 +93,8 @@ public class TASmod implements ModInitializer, EventServerStart, EventServerInit public static KTRNGSeedStorage seedStorage = new KTRNGSeedStorage(); + public static MathRandomness mathRandomness = new MathRandomness(0); + @Override public void onInitialize() { @@ -144,6 +147,7 @@ public void onInitialize() { public void onServerStart(MinecraftServer server) { globalRandomness = new GlobalRandomnessTimer(); EventListenerRegistry.register(globalRandomness); + mathRandomness = new MathRandomness(); } @Override diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java new file mode 100644 index 00000000..686b5f91 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java @@ -0,0 +1,19 @@ +package com.minecrafttas.tasmod.ktrng; + +import com.minecrafttas.tasmod.TASmod; + +/** + *

Randomness instance for hooking into {@link Math#random()} + * + * @author Scribble + */ +public class MathRandomness extends RandomBase { + + public MathRandomness() { + super(TASmod.globalRandomness.getCurrentSeed()); + } + + public MathRandomness(long seed) { + super(seed); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java new file mode 100644 index 00000000..c863101c --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java @@ -0,0 +1,21 @@ +package com.minecrafttas.tasmod.mixin.killtherng.mathrand; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.entity.item.EntityItem; +import net.minecraft.world.World; + +@Mixin(EntityItem.class) +public class MixinEntityItem { + + @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) + private double wrap_entityItemInit(Operation original, World world, double d, double e, double f) { + System.out.println("Test"); + return TASmod.mathRandomness.nextDouble(); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java new file mode 100644 index 00000000..95f705a1 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java @@ -0,0 +1,19 @@ +package com.minecrafttas.tasmod.mixin.killtherng.mathrand; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.entity.EntityLivingBase; + +@Mixin(EntityLivingBase.class) +public class MixinEntityLivingBase { + + @WrapOperation(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) + private double wrap_attackEntityFrom(Operation original) { + return TASmod.mathRandomness.nextDouble(); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index b1ee3dd6..4a2324a5 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -59,6 +59,8 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { dataToSave.add("worldRandom", worldRandomDataJson); + dataToSave.addProperty("mathRandom", Long.toString(TASmod.mathRandomness.getSeed())); + return dataToSave; } @@ -103,6 +105,8 @@ public void onLoadstateComplete(MinecraftServer server, JsonObject loadedData) { } KTRNGWorldHandler.setWorldRandomnessMap(worldList); + + TASmod.mathRandomness.setSeed(loadedData.get("mathRandom").getAsLong()); } @Override diff --git a/src/main/resources/tasmod.mixin.json b/src/main/resources/tasmod.mixin.json index f7c7ec7b..59d2f410 100644 --- a/src/main/resources/tasmod.mixin.json +++ b/src/main/resources/tasmod.mixin.json @@ -24,7 +24,9 @@ "fixes.MixinDragonFightManager", "killtherng.MixinEntity", - "killtherng.MixinWorld" + "killtherng.MixinWorld", + "killtherng.mathrand.MixinEntityLivingBase", + "killtherng.mathrand.MixinEntityItem" ], "client": [ From 9d874d61e62e2e49b0a9e0824822c6fc01b67c04 Mon Sep 17 00:00:00 2001 From: Scribble Date: Tue, 2 Dec 2025 19:25:54 +0100 Subject: [PATCH 20/26] [KillTheRNG] Finish MathRandomness --- .../tasmod/mixin/MixinMinecraftServer.java | 25 ++++++++++--------- .../killtherng/mathrand/MixinEntityItem.java | 1 - .../mathrand/MixinEntityLivingBase.java | 6 +++++ .../mathrand/MixinEntityTNTPrimed.java | 21 ++++++++++++++++ .../killtherng/mathrand/MixinEntityXPOrb.java | 20 +++++++++++++++ .../mathrand/MixinWorldEntitySpawner.java | 20 +++++++++++++++ src/main/resources/tasmod.mixin.json | 5 +++- 7 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityXPOrb.java create mode 100644 src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java index 09876ee0..5a57d75d 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/MixinMinecraftServer.java @@ -13,6 +13,7 @@ import com.minecrafttas.mctcommon.events.EventListenerRegistry; import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.events.EventServer.EventServerTickPost; +import com.minecrafttas.tasmod.savestates.SavestateHandlerServer.SavestateState; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -109,18 +110,18 @@ public void redirectThreadSleep(long msToTick) { TASmod.gameLoopSchedulerServer.runAllTasks(); -// boolean stopTaskQueue = TASmod.savestateHandlerServer != null && TASmod.savestateHandlerServer.getState() == SavestateState.LOADING; -// if (!stopTaskQueue) { -// synchronized (this.futureTaskQueue) { -// while (!this.futureTaskQueue.isEmpty()) { -// try { -// ((FutureTask) this.futureTaskQueue.poll()).run(); -// } catch (Throwable var9) { -// var9.printStackTrace(); -// } -// } -// } -// } + boolean stopTaskQueue = TASmod.savestateHandlerServer != null && TASmod.savestateHandlerServer.getState() == SavestateState.LOADING; + if (!stopTaskQueue) { + synchronized (this.futureTaskQueue) { + while (!this.futureTaskQueue.isEmpty()) { + try { + ((FutureTask) this.futureTaskQueue.poll()).run(); + } catch (Throwable var9) { + var9.printStackTrace(); + } + } + } + } } @Environment(EnvType.SERVER) diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java index c863101c..a94c9bf5 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityItem.java @@ -15,7 +15,6 @@ public class MixinEntityItem { @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) private double wrap_entityItemInit(Operation original, World world, double d, double e, double f) { - System.out.println("Test"); return TASmod.mathRandomness.nextDouble(); } } diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java index 95f705a1..2d882de9 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityLivingBase.java @@ -8,10 +8,16 @@ import com.minecrafttas.tasmod.TASmod; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.world.World; @Mixin(EntityLivingBase.class) public class MixinEntityLivingBase { + @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) + private double wrap_entityLivingBase(Operation original, World world) { + return TASmod.mathRandomness.nextDouble(); + } + @WrapOperation(method = "attackEntityFrom", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) private double wrap_attackEntityFrom(Operation original) { return TASmod.mathRandomness.nextDouble(); diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java new file mode 100644 index 00000000..bd8fec2d --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java @@ -0,0 +1,21 @@ +package com.minecrafttas.tasmod.mixin.killtherng.mathrand; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityTNTPrimed; +import net.minecraft.world.World; + +@Mixin(EntityTNTPrimed.class) +public class MixinEntityTNTPrimed { + + @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) + private double wrap_entityTNTPrimedInit(Operation original, World world, double d, double e, double f, EntityLivingBase entityLivingBase) { + return TASmod.mathRandomness.nextDouble(); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityXPOrb.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityXPOrb.java new file mode 100644 index 00000000..ed776195 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityXPOrb.java @@ -0,0 +1,20 @@ +package com.minecrafttas.tasmod.mixin.killtherng.mathrand; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.world.World; + +@Mixin(EntityXPOrb.class) +public class MixinEntityXPOrb { + + @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) + private double wrap_entityXPOrb(Operation original, World world, double d, double e, double f, int i) { + return TASmod.mathRandomness.nextDouble(); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java new file mode 100644 index 00000000..e4c718ca --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java @@ -0,0 +1,20 @@ +package com.minecrafttas.tasmod.mixin.killtherng.mathrand; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.minecrafttas.tasmod.TASmod; + +import net.minecraft.world.WorldEntitySpawner; +import net.minecraft.world.WorldServer; + +@Mixin(WorldEntitySpawner.class) +public class MixinWorldEntitySpawner { + + @WrapOperation(method = "findChunksForSpawning", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) + private double wrap_worldEntitySpawnerFindChunks(Operation original, WorldServer worldServer, boolean bl, boolean bl2, boolean bl3) { + return TASmod.mathRandomness.nextDouble(); + } +} diff --git a/src/main/resources/tasmod.mixin.json b/src/main/resources/tasmod.mixin.json index 59d2f410..2daed941 100644 --- a/src/main/resources/tasmod.mixin.json +++ b/src/main/resources/tasmod.mixin.json @@ -26,7 +26,10 @@ "killtherng.MixinEntity", "killtherng.MixinWorld", "killtherng.mathrand.MixinEntityLivingBase", - "killtherng.mathrand.MixinEntityItem" + "killtherng.mathrand.MixinEntityItem", + "killtherng.mathrand.MixinEntityXPOrb", + "killtherng.mathrand.MixinEntityTNTPrimed", + "killtherng.mathrand.MixinWorldEntitySpawner" ], "client": [ From f9afa2debc80c027967f57a4e57155098d98d358 Mon Sep 17 00:00:00 2001 From: Scribble Date: Wed, 11 Feb 2026 22:07:07 +0100 Subject: [PATCH 21/26] [KillTheRNG] Fix world setSeed in place --- src/main/java/com/minecrafttas/tasmod/TASmod.java | 3 +++ .../tasmod/ktrng/WorldSeedRandomness.java | 12 ++++++++++++ .../tasmod/mixin/killtherng/MixinWorld.java | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index 302f0860..b2678cc7 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -27,6 +27,7 @@ import com.minecrafttas.tasmod.handlers.PlayUntilHandler; import com.minecrafttas.tasmod.ktrng.GlobalRandomnessTimer; import com.minecrafttas.tasmod.ktrng.MathRandomness; +import com.minecrafttas.tasmod.ktrng.WorldSeedRandomness; import com.minecrafttas.tasmod.playback.PlaybackControllerServer; import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension; import com.minecrafttas.tasmod.registries.TASmodAPIRegistry; @@ -95,6 +96,8 @@ public class TASmod implements ModInitializer, EventServerStart, EventServerInit public static MathRandomness mathRandomness = new MathRandomness(0); + public static WorldSeedRandomness worldSeedRandomness = new WorldSeedRandomness(); + @Override public void onInitialize() { diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java new file mode 100644 index 00000000..f4530c27 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java @@ -0,0 +1,12 @@ +package com.minecrafttas.tasmod.ktrng; + +public class WorldSeedRandomness extends RandomBase { + + public WorldSeedRandomness() { + super(); + } + + public WorldSeedRandomness(long seed) { + super(seed); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java index 8a710c49..972e519c 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java @@ -6,6 +6,9 @@ import org.spongepowered.asm.mixin.injection.At; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.ModifyReceiver; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.ktrng.WorldRandomness; import net.minecraft.world.World; @@ -17,4 +20,14 @@ public class MixinWorld { public Random modify_worldRandom(Random original) { return new WorldRandomness(); } + + @ModifyReceiver(method = "setRandomSeed", at = @At(value = "INVOKE", target = "Ljava/util/Random;setSeed(J)V")) + public Random modify_worldSetRNGRandom(Random original, long seed) { + return TASmod.worldSeedRandomness; + } + + @ModifyReturnValue(method = "setRandomSeed", at = @At(value = "RETURN")) + public Random modify_worldSetRNGReturn(Random original) { + return TASmod.worldSeedRandomness; + } } From 0b5f2b9f7c155fd6f2bd529b735b612c992bda3b Mon Sep 17 00:00:00 2001 From: Scribble Date: Fri, 6 Mar 2026 18:48:21 +0100 Subject: [PATCH 22/26] [KillTheRNG] Add DebugRand output --- .../java/com/minecrafttas/tasmod/TASmod.java | 6 +- .../minecrafttas/tasmod/ktrng/DebugRand.java | 72 +++++++++++++++++++ .../tasmod/ktrng/MathRandomness.java | 5 ++ .../minecrafttas/tasmod/ktrng/RandomBase.java | 28 ++++++-- .../tasmod/ktrng/WorldRandomness.java | 2 +- .../tasmod/ktrng/WorldSeedRandomness.java | 8 +-- .../tasmod/mixin/killtherng/MixinWorld.java | 6 +- 7 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index b2678cc7..09130d8d 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -25,6 +25,7 @@ import com.minecrafttas.tasmod.commands.CommandSavestate; import com.minecrafttas.tasmod.commands.CommandTickrate; import com.minecrafttas.tasmod.handlers.PlayUntilHandler; +import com.minecrafttas.tasmod.ktrng.DebugRand; import com.minecrafttas.tasmod.ktrng.GlobalRandomnessTimer; import com.minecrafttas.tasmod.ktrng.MathRandomness; import com.minecrafttas.tasmod.ktrng.WorldSeedRandomness; @@ -96,7 +97,9 @@ public class TASmod implements ModInitializer, EventServerStart, EventServerInit public static MathRandomness mathRandomness = new MathRandomness(0); - public static WorldSeedRandomness worldSeedRandomness = new WorldSeedRandomness(); + public static WorldSeedRandomness worldSeedRandomness = new WorldSeedRandomness(0); + + public static DebugRand debugRand = new DebugRand(); @Override public void onInitialize() { @@ -124,6 +127,7 @@ public void onInitialize() { EventListenerRegistry.register(ticksyncServer); EventListenerRegistry.register(tickratechanger); // EventListenerRegistry.register(ktrngHandler); + EventListenerRegistry.register(debugRand); // Register packet handlers LOGGER.info(LoggerMarkers.Networking, "Registering network handlers"); diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java b/src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java new file mode 100644 index 00000000..d74790fd --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java @@ -0,0 +1,72 @@ +package com.minecrafttas.tasmod.ktrng; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import com.minecrafttas.mctcommon.events.EventServer; +import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.events.EventPlaybackServer; +import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; +import com.minecrafttas.tasmod.util.FileThread; + +import net.minecraft.server.MinecraftServer; + +public class DebugRand implements EventPlaybackServer.EventControllerStateChange, EventServer.EventServerTick { + + private FileThread thread = null; + + public void writeDebug(String out) { + if (thread != null && TASmod.isDevEnvironment) { + thread.addLine(out); + } + } + + public boolean isActive() { + return thread != null; + } + + @Override + public void onControllerStateChange(TASstate newstate, TASstate oldstate) { + Path serverDir = TASmod.getServerInstance().getDataDirectory().toPath(); + + if (isActive()) { + thread.close(); + thread = null; + } + + if (newstate == TASstate.RECORDING) { + try { + thread = new FileThread(serverDir.resolve("ktrng_recording.txt"), false); + thread.start(); + } catch (IOException e) { + e.printStackTrace(); + } + } else if (newstate == TASstate.PLAYBACK) { + + Path playbackFile = serverDir.resolve("ktrng_playback.txt"); + + if (Files.exists(playbackFile)) { + int i = 0; + do { + i++; + playbackFile = serverDir.resolve(String.format("ktrng_playback%s.txt", i)); + } while (Files.exists(playbackFile)); + } + + try { + thread = new FileThread(playbackFile, false); + thread.start(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + @Override + public void onServerTick(MinecraftServer server) { + if (isActive()) { + thread.addLine(""); + } + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java index 686b5f91..23248891 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java @@ -16,4 +16,9 @@ public MathRandomness() { public MathRandomness(long seed) { super(seed); } + + @Override + public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { +// super.fireEvent(eventType, seed, value, stackTraceOffset); + } } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 8f2be415..97d6ded6 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -3,7 +3,7 @@ import java.util.Random; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.util.LoggerMarkers; +import com.minecrafttas.tasmod.util.FileThread; import kaptainwutax.seedutils.lcg.LCG; import kaptainwutax.seedutils.rand.JRand; @@ -19,6 +19,7 @@ public class RandomBase extends Random { private boolean client; private long initialSeed; + public static FileThread writerThread; public RandomBase() { super(); @@ -182,7 +183,7 @@ public boolean equals(Object obj) { } public void fireSetEvent(String eventType, long seed, String value, int stackTraceOffset) { - fireEvent(eventType, seed, value, stackTraceOffset); +// fireEvent(eventType, seed, value, stackTraceOffset); } public void fireGetEvent(String eventType, long seed, String value) { @@ -190,16 +191,31 @@ public void fireGetEvent(String eventType, long seed, String value) { } public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { - StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[stackTraceOffset]; + if (!TASmod.debugRand.isActive()) { + return; + } + + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + List classOut = new ArrayList<>(); + for (int i = stackTraceOffset; i < stackTraceOffset + 4; i++) { + String out = formatStackTraceElement(stackTraceElements[i]); + if (out != null) + classOut.add(out); + } + String out = String.format("%s %s %s\t%s\t%s", eventType, seed, value, this.getClass().getSimpleName(), String.join(", ", classOut)); + TASmod.debugRand.writeDebug(out); + } + + private String formatStackTraceElement(StackTraceElement stackTraceElement) { String methodName = stackTraceElement.getMethodName(); String[] classNames = stackTraceElement.getClassName().split("\\."); String className = classNames[classNames.length - 1]; if (methodName.equals("showBarrierParticles")) - return; - String out = className + "." + methodName + + return null; + String classOut = className + "." + methodName + (stackTraceElement.isNativeMethod() ? "(Native Method)" : (stackTraceElement.getFileName() != null && stackTraceElement.getLineNumber() >= 0 ? "(" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + ")" : (stackTraceElement.getFileName() != null ? "(" + stackTraceElement.getFileName() + ")" : "(Unknown Source)"))); - TASmod.LOGGER.debug(LoggerMarkers.KillTheRNG, "{} {}\t{}\t{}", eventType, seed, value, out); + return classOut; } public long getInitialSeed() { diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java index 01a51b7c..28a52d49 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java @@ -14,6 +14,6 @@ public WorldRandomness() { @Override public void fireEvent(String val, long seed, String value, int offset) { - //super.fireEvent(val, seed, value, 5); + super.fireEvent(val, seed, value, 5); } } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java index f4530c27..e993f674 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java @@ -2,11 +2,11 @@ public class WorldSeedRandomness extends RandomBase { - public WorldSeedRandomness() { - super(); - } - public WorldSeedRandomness(long seed) { super(seed); } + + @Override + public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { + } } diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java index 972e519c..a783c2d1 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java @@ -12,13 +12,17 @@ import com.minecrafttas.tasmod.ktrng.WorldRandomness; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; @Mixin(World.class) public class MixinWorld { @ModifyExpressionValue(method = "", at = @At(value = "NEW", target = "Ljava/util/Random;")) public Random modify_worldRandom(Random original) { - return new WorldRandomness(); + if (((World) (Object) this) instanceof WorldServer) + return new WorldRandomness(); + else + return original; } @ModifyReceiver(method = "setRandomSeed", at = @At(value = "INVOKE", target = "Ljava/util/Random;setSeed(J)V")) From b4fd3da977abd5a518a0e783ed7f754317fd344e Mon Sep 17 00:00:00 2001 From: Scribble Date: Fri, 6 Mar 2026 18:48:21 +0100 Subject: [PATCH 23/26] [KillTheRNG] Switch to Jrand --- .../java/com/minecrafttas/tasmod/TASmod.java | 2 +- .../tasmod/ktrng/EntityRandomness.java | 5 + .../tasmod/ktrng/MathRandomness.java | 2 +- .../minecrafttas/tasmod/ktrng/RandomBase.java | 117 +++++++----------- .../tasmod/killtherng/RandomBaseTest.java | 77 ++++++++++++ 5 files changed, 129 insertions(+), 74 deletions(-) create mode 100644 src/test/java/tasmod/killtherng/RandomBaseTest.java diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index 09130d8d..d7c80bd1 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -154,7 +154,7 @@ public void onInitialize() { public void onServerStart(MinecraftServer server) { globalRandomness = new GlobalRandomnessTimer(); EventListenerRegistry.register(globalRandomness); - mathRandomness = new MathRandomness(); + mathRandomness = new MathRandomness(0); } @Override diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java index a5de00bf..b78aa182 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java @@ -13,4 +13,9 @@ public EntityRandomness() { public EntityRandomness(long seed) { super(seed); } + + @Override + public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { +// super.fireEvent(eventType, seed, value, stackTraceOffset); + } } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java index 23248891..9d493129 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java @@ -19,6 +19,6 @@ public MathRandomness(long seed) { @Override public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { -// super.fireEvent(eventType, seed, value, stackTraceOffset); + super.fireEvent(eventType, seed, value, 6); } } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 97d6ded6..199ce0ad 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -1,5 +1,7 @@ package com.minecrafttas.tasmod.ktrng; +import java.util.ArrayList; +import java.util.List; import java.util.Random; import com.minecrafttas.tasmod.TASmod; @@ -13,126 +15,104 @@ public class RandomBase extends Random { private String name; private String description; - private long timesCalled = 0; - - private boolean enabled; - private boolean client; - private long initialSeed; public static FileThread writerThread; - public RandomBase() { - super(); - } + private JRand.Debugger jrand; public RandomBase(long seed) { super(seed); this.initialSeed = seed; + jrand = new JRand(seed, false).asDebugger(); } @Override public void setSeed(long seedIn) { - setSeed(seedIn, true); - } - - public void setSeed(long seedIn, boolean shouldLog) { - if (shouldLog) - fireSetEvent("setSeed()", seedIn, "", 8); - super.setSeed(seedIn ^ 0x5deece66dL); + super.setSeed(seedIn); + if (jrand != null) + jrand.setSeed(seedIn, false); +// super.setSeed(seedIn ^ 0x5deece66dL); } public long getSeed() { - long saved = timesCalled; - long seed = reverse(super.nextLong()) ^ 0x5deece66dL; - super.setSeed(seed); - timesCalled = saved; - return seed ^ 0x5deece66dL; - } - - public static long reverse(long in) { - return (((7847617 * ((24667315 * (in >>> 32) + 18218081 * (in & 0xffffffffL) + 67552711) >> 32) - 18218081 * ((-4824621 * (in >>> 32) + 7847617 * (in & 0xffffffffL) + 7847617) >> 32)) - 11) * 246154705703781L) & 0xffffffffffffL; - } - - public String getName() { - return this.name; - } - - public String getDescription() { - return description; - } - - public long getTimesCalled() { - return timesCalled; - } - - public boolean isEnabled() { - return enabled; - } - - public boolean isClient() { - return client; - } +// long saved = timesCalled; +// long seed = reverse(super.nextLong()) ^ 0x5deece66dL; +// super.setSeed(seed); +// timesCalled = saved; +// return seed ^ 0x5deece66dL; + return jrand.getSeed(); + } + +// public static long reverse(long in) { +// return (((7847617 * ((24667315 * (in >>> 32) + 18218081 * (in & 0xffffffffL) + 67552711) >> 32) - 18218081 * ((-4824621 * (in >>> 32) + 7847617 * (in & 0xffffffffL) + 7847617) >> 32)) - 11) * 246154705703781L) & 0xffffffffffffL; +// } + +// public String getName() { +// return this.name; +// } +// +// public String getDescription() { +// return description; +// } + +// public long getTimesCalled() { +// return timesCalled; +// } @Override public long nextLong() { - timesCalled++; +// timesCalled++; long seedstored = getSeed(); - long value = super.nextLong(); + long value = jrand.nextLong(); fireGetEvent("nextLong()", seedstored, Long.toString(value)); return value; } @Override public double nextDouble() { - timesCalled++; +// timesCalled++; long seedstored = getSeed(); - double value = super.nextDouble(); + double value = jrand.nextDouble(); fireGetEvent("nextDouble()", seedstored, Double.toString(value)); return value; } @Override public boolean nextBoolean() { - timesCalled++; +// timesCalled++; long seedstored = getSeed(); - boolean value = super.nextBoolean(); + boolean value = jrand.nextBoolean(); fireGetEvent("nextBoolean()", seedstored, Boolean.toString(value)); return value; } @Override public int nextInt() { - timesCalled++; +// timesCalled++; long seedstored = getSeed(); - int value = super.nextInt(); + int value = jrand.nextInt(); fireGetEvent("nextInt()", seedstored, Integer.toString(value)); return value; } @Override public int nextInt(int bound) { - timesCalled++; +// timesCalled++; long seedstored = getSeed(); - int value = super.nextInt(bound); + int value = jrand.nextInt(bound); fireGetEvent(String.format("nextInt(%s)", bound), seedstored, Integer.toString(value)); return value; } @Override public float nextFloat() { - return super.nextFloat(); - } - - @Override - public void nextBytes(byte[] bytes) { - super.nextBytes(bytes); + return jrand.nextFloat(); } @Override public double nextGaussian() { - timesCalled++; double value = 0; - value = super.nextGaussian(); + value = jrand.nextGaussian(); return value; } @@ -141,14 +121,7 @@ public void advance() { } public void advance(long i) { - JRand thing = JRand.ofInternalSeed(getSeed()); - thing.advance(i); - setSeed(thing.getSeed(), false); - } - - public long getSeedAt(int steps) { - JRand thing = new JRand(getSeed()).combine(steps); - return thing.getSeed(); + jrand.advance(i); } public long distance(RandomBase random) { @@ -187,7 +160,7 @@ public void fireSetEvent(String eventType, long seed, String value, int stackTra } public void fireGetEvent(String eventType, long seed, String value) { - //fireEvent(eventType, seed, value, 3); +// fireEvent(eventType, seed, value, 3); } public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { diff --git a/src/test/java/tasmod/killtherng/RandomBaseTest.java b/src/test/java/tasmod/killtherng/RandomBaseTest.java new file mode 100644 index 00000000..38f0966c --- /dev/null +++ b/src/test/java/tasmod/killtherng/RandomBaseTest.java @@ -0,0 +1,77 @@ +package tasmod.killtherng; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.minecrafttas.tasmod.ktrng.RandomBase; + +import kaptainwutax.seedutils.rand.JRand; + +class RandomBaseTest { + + @BeforeEach + void setUp() throws Exception { + } + + @Test + void testInitialSeed() { + long expected = 12345L; + RandomBase testRandom = new RandomBase(expected); + long actual = testRandom.getSeed(); + assertEquals(12345L, actual); + } + + @Test + void testSetSeed() { + RandomBase testRandom = new RandomBase(1L); + testRandom.setSeed(12345L); + assertEquals(12345L, testRandom.getSeed()); + } + + @Test + void testAdvance() { + JRand thing = JRand.ofInternalSeed(12345L); + RandomBase testRandom = new RandomBase(12345L); + + testRandom.advance(); + thing.advance(1); + + assertEquals(thing.getSeed(), testRandom.getSeed()); + } + + @Test + void testAdvancingLong() { + JRand thing = JRand.ofInternalSeed(12345L); + RandomBase testRandom = new RandomBase(12345L); + + long expectedValue = thing.nextLong(); + long actualValue = testRandom.nextLong(); + + assertEquals(expectedValue, actualValue); + assertEquals(thing.getSeed(), testRandom.getSeed()); + } + + @Test + void testAdvancingLong2() { + JRand thing = JRand.ofInternalSeed(12345L); + RandomBase testRandom = new RandomBase(12345L); + + testRandom.nextLong(); + thing.advance(2); + + assertEquals(thing.getSeed(), testRandom.getSeed()); + } + + @Test + void testAdvancingDifferentRNGs() { + RandomBase testRandom1 = new RandomBase(12345L); + RandomBase testRandom2 = new RandomBase(12345L); + + testRandom1.nextInt(); + testRandom2.nextInt(6); + + assertEquals(testRandom1.getSeed(), testRandom2.getSeed()); + } +} From 078da1f133b201ccce236942f3237059e3b51275 Mon Sep 17 00:00:00 2001 From: Scribble Date: Mon, 9 Mar 2026 20:54:06 +0100 Subject: [PATCH 24/26] [KillTheRNG] Cleanup and rename classes --- .../java/com/minecrafttas/tasmod/TASmod.java | 8 +-- .../tasmod/events/EventKillTheRNGServer.java | 12 ++++ .../com/minecrafttas/tasmod/gui/InfoHud.java | 13 +++- .../minecrafttas/tasmod/ktrng/DebugRand.java | 72 ------------------- .../tasmod/ktrng/EntityRandomness.java | 21 ------ .../tasmod/ktrng/GlobalRandomnessTimer.java | 7 +- .../ktrng/GlobalRandomnessTimerClient.java | 11 +-- .../tasmod/ktrng/KTRNGMonitor.java | 10 --- .../tasmod/ktrng/KillTheRNGHandler.java | 4 ++ .../tasmod/ktrng/MathRandomness.java | 24 ------- .../minecrafttas/tasmod/ktrng/RandomBase.java | 68 ++++++------------ .../tasmod/ktrng/WorldRandomness.java | 19 ----- .../tasmod/ktrng/WorldSeedRandomness.java | 12 ---- .../ktrng/builtin/EntityRandomness.java | 24 +++++++ .../tasmod/ktrng/builtin/MathRandomness.java | 29 ++++++++ .../tasmod/ktrng/builtin/WorldRandomness.java | 24 +++++++ .../ktrng/builtin/WorldSeedRandomness.java | 23 ++++++ .../ktrng/events/KillTheRNGMonitor.java | 32 +++++++++ .../{ => handlers}/KTRNGEntityHandler.java | 3 +- .../{ => handlers}/KTRNGWorldHandler.java | 3 +- .../tasmod/mixin/killtherng/MixinEntity.java | 5 +- .../tasmod/mixin/killtherng/MixinWorld.java | 2 +- .../mathrand/MixinWorldEntitySpawner.java | 3 +- .../savestates/files/SavestateDataFile.java | 8 +++ .../SavestateStorageExtensionRegistry.java | 2 +- .../storage/builtin/KTRNGSeedStorage.java | 13 ++-- src/test/java/tasmod/killtherng/RNGTest.java | 5 +- .../tasmod/killtherng/RandomBaseTest.java | 33 ++++++--- 28 files changed, 246 insertions(+), 244 deletions(-) create mode 100644 src/main/java/com/minecrafttas/tasmod/events/EventKillTheRNGServer.java delete mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java delete mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java delete mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGMonitor.java delete mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java delete mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java delete mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/builtin/EntityRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/builtin/MathRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldSeedRandomness.java create mode 100644 src/main/java/com/minecrafttas/tasmod/ktrng/events/KillTheRNGMonitor.java rename src/main/java/com/minecrafttas/tasmod/ktrng/{ => handlers}/KTRNGEntityHandler.java (90%) rename src/main/java/com/minecrafttas/tasmod/ktrng/{ => handlers}/KTRNGWorldHandler.java (94%) diff --git a/src/main/java/com/minecrafttas/tasmod/TASmod.java b/src/main/java/com/minecrafttas/tasmod/TASmod.java index d7c80bd1..5db58343 100644 --- a/src/main/java/com/minecrafttas/tasmod/TASmod.java +++ b/src/main/java/com/minecrafttas/tasmod/TASmod.java @@ -25,10 +25,10 @@ import com.minecrafttas.tasmod.commands.CommandSavestate; import com.minecrafttas.tasmod.commands.CommandTickrate; import com.minecrafttas.tasmod.handlers.PlayUntilHandler; -import com.minecrafttas.tasmod.ktrng.DebugRand; import com.minecrafttas.tasmod.ktrng.GlobalRandomnessTimer; -import com.minecrafttas.tasmod.ktrng.MathRandomness; -import com.minecrafttas.tasmod.ktrng.WorldSeedRandomness; +import com.minecrafttas.tasmod.ktrng.builtin.MathRandomness; +import com.minecrafttas.tasmod.ktrng.builtin.WorldSeedRandomness; +import com.minecrafttas.tasmod.ktrng.events.KillTheRNGMonitor; import com.minecrafttas.tasmod.playback.PlaybackControllerServer; import com.minecrafttas.tasmod.playback.metadata.builtin.StartpositionMetadataExtension; import com.minecrafttas.tasmod.registries.TASmodAPIRegistry; @@ -99,7 +99,7 @@ public class TASmod implements ModInitializer, EventServerStart, EventServerInit public static WorldSeedRandomness worldSeedRandomness = new WorldSeedRandomness(0); - public static DebugRand debugRand = new DebugRand(); + public static KillTheRNGMonitor debugRand = new KillTheRNGMonitor(); @Override public void onInitialize() { diff --git a/src/main/java/com/minecrafttas/tasmod/events/EventKillTheRNGServer.java b/src/main/java/com/minecrafttas/tasmod/events/EventKillTheRNGServer.java new file mode 100644 index 00000000..555f5a12 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/events/EventKillTheRNGServer.java @@ -0,0 +1,12 @@ +package com.minecrafttas.tasmod.events; + +import com.minecrafttas.mctcommon.events.EventListenerRegistry.EventBase; +import com.minecrafttas.tasmod.ktrng.RandomBase.RNGSide; + +public interface EventKillTheRNGServer { + + @FunctionalInterface + public interface EventRNG extends EventBase { + public void onRNGCall(RNGSide side, String eventType, long seed, String value, StackTraceElement[] stackTraceElements); + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java index 37758dd3..8ad4131f 100644 --- a/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java +++ b/src/main/java/com/minecrafttas/tasmod/gui/InfoHud.java @@ -18,7 +18,7 @@ import com.minecrafttas.tasmod.TASmod; import com.minecrafttas.tasmod.TASmodClient; import com.minecrafttas.tasmod.events.EventClient.EventDrawHotbar; -import com.minecrafttas.tasmod.ktrng.KTRNGWorldHandler; +import com.minecrafttas.tasmod.ktrng.handlers.KTRNGWorldHandler; import com.minecrafttas.tasmod.playback.PlaybackControllerClient; import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; import com.minecrafttas.tasmod.playback.filecommands.builtin.DesyncMonitorFileCommandExtension; @@ -329,6 +329,17 @@ public boolean checkInit() { return "WorldRNG: " + KTRNGWorldHandler.getWorldRandom(); })); + y += 14; + title = "ktrng_mathseed"; + if (configuration.getProperty(title + "_x", "err").equals("err")) + setDefaults(title, y); + lists.add(new InfoLabel(title, Integer.parseInt(configuration.getProperty(title + "_x")), Integer.parseInt(configuration.getProperty(title + "_y")), Boolean.parseBoolean(configuration.getProperty(title + + "_visible")), Boolean.parseBoolean(configuration.getProperty(title + "_rect")), () -> { + if (Minecraft.getMinecraft().currentScreen == this) + return "MathRNG"; + return "MathRNG: " + TASmod.mathRandomness.getSeed(); + })); + title = "facing"; y += 14; if (configuration.getProperty(title + "_x", "err").equals("err")) diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java b/src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java deleted file mode 100644 index d74790fd..00000000 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/DebugRand.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.minecrafttas.tasmod.ktrng; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -import com.minecrafttas.mctcommon.events.EventServer; -import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.events.EventPlaybackServer; -import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; -import com.minecrafttas.tasmod.util.FileThread; - -import net.minecraft.server.MinecraftServer; - -public class DebugRand implements EventPlaybackServer.EventControllerStateChange, EventServer.EventServerTick { - - private FileThread thread = null; - - public void writeDebug(String out) { - if (thread != null && TASmod.isDevEnvironment) { - thread.addLine(out); - } - } - - public boolean isActive() { - return thread != null; - } - - @Override - public void onControllerStateChange(TASstate newstate, TASstate oldstate) { - Path serverDir = TASmod.getServerInstance().getDataDirectory().toPath(); - - if (isActive()) { - thread.close(); - thread = null; - } - - if (newstate == TASstate.RECORDING) { - try { - thread = new FileThread(serverDir.resolve("ktrng_recording.txt"), false); - thread.start(); - } catch (IOException e) { - e.printStackTrace(); - } - } else if (newstate == TASstate.PLAYBACK) { - - Path playbackFile = serverDir.resolve("ktrng_playback.txt"); - - if (Files.exists(playbackFile)) { - int i = 0; - do { - i++; - playbackFile = serverDir.resolve(String.format("ktrng_playback%s.txt", i)); - } while (Files.exists(playbackFile)); - } - - try { - thread = new FileThread(playbackFile, false); - thread.start(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - @Override - public void onServerTick(MinecraftServer server) { - if (isActive()) { - thread.addLine(""); - } - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java deleted file mode 100644 index b78aa182..00000000 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/EntityRandomness.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.minecrafttas.tasmod.ktrng; - -import com.minecrafttas.tasmod.TASmod; - -public class EntityRandomness extends RandomBase { - - public static long entityCount = 0; - - public EntityRandomness() { - super(TASmod.globalRandomness.getCurrentSeed()); - } - - public EntityRandomness(long seed) { - super(seed); - } - - @Override - public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { -// super.fireEvent(eventType, seed, value, stackTraceOffset); - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java index 6d64417b..50165528 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimer.java @@ -2,21 +2,22 @@ import com.minecrafttas.mctcommon.events.EventServer; +import kaptainwutax.seedutils.rand.JRand; import net.minecraft.server.MinecraftServer; public class GlobalRandomnessTimer implements EventServer.EventServerTick { - private final RandomBase globalRandomness; + private final JRand globalRandomness; private long currentSeed = 0L; public GlobalRandomnessTimer() { - globalRandomness = new RandomBase(0L); + globalRandomness = new JRand(0L); } @Override public void onServerTick(MinecraftServer server) { - globalRandomness.advance(); + globalRandomness.advance(1); currentSeed = globalRandomness.getSeed(); } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java index ea94251c..85bb41d8 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/GlobalRandomnessTimerClient.java @@ -2,18 +2,19 @@ import com.minecrafttas.mctcommon.events.EventClient; +import kaptainwutax.seedutils.rand.JRand; import net.minecraft.client.Minecraft; public class GlobalRandomnessTimerClient implements EventClient.EventClientTick { - private final RandomBase globalRandomness; - private final RandomBase uuidRandomness; + private final JRand globalRandomness; + private final JRand uuidRandomness; private long currentSeed = 0L; public GlobalRandomnessTimerClient() { - globalRandomness = new RandomBase(0L); - uuidRandomness = new RandomBase(0L); + globalRandomness = new JRand(0L); + uuidRandomness = new JRand(0L); } @Override @@ -26,7 +27,7 @@ public long getCurrentSeed() { return currentSeed; } - public RandomBase getUUIDRandom() { + public JRand getUUIDRandom() { return uuidRandomness; } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGMonitor.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGMonitor.java deleted file mode 100644 index 7cf6fa98..00000000 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGMonitor.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.minecrafttas.tasmod.ktrng; - -@Deprecated -public class KTRNGMonitor { - -// @CaptureRandomness(name = "jukeboxRecordDropPosition") - public static void monitor(long seed, String value) { -// System.out.println(String.format("Seed: %s, Value: %s", seed, value)); - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java index 18926f41..501501af 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java @@ -39,6 +39,7 @@ public class KillTheRNGHandler implements EventServerTick, EventPlayerJoinedClie * * @param isLoaded If the KillTheRNG mod is loaded */ + @Deprecated public KillTheRNGHandler(boolean isLoaded) { this.isLoaded = isLoaded; @@ -53,6 +54,7 @@ public KillTheRNGHandler(boolean isLoaded) { } } + @Deprecated public long advanceGlobalSeedServer() { // if (isLoaded()) { // return KillTheRNG.commonRandom.nextSeed(); @@ -61,6 +63,7 @@ public long advanceGlobalSeedServer() { // } } + @Deprecated public long getGlobalSeedServer() { // if (isLoaded()) { // return KillTheRNG.commonRandom.GlobalServer.getSeed(); @@ -69,6 +72,7 @@ public long getGlobalSeedServer() { // } } + @Deprecated public boolean isLoaded() { return isLoaded; } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java deleted file mode 100644 index 9d493129..00000000 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/MathRandomness.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.minecrafttas.tasmod.ktrng; - -import com.minecrafttas.tasmod.TASmod; - -/** - *

Randomness instance for hooking into {@link Math#random()} - * - * @author Scribble - */ -public class MathRandomness extends RandomBase { - - public MathRandomness() { - super(TASmod.globalRandomness.getCurrentSeed()); - } - - public MathRandomness(long seed) { - super(seed); - } - - @Override - public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { - super.fireEvent(eventType, seed, value, 6); - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 199ce0ad..c75f9f9e 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -1,29 +1,29 @@ package com.minecrafttas.tasmod.ktrng; -import java.util.ArrayList; -import java.util.List; import java.util.Random; +import com.minecrafttas.mctcommon.events.EventListenerRegistry; +import com.minecrafttas.mctcommon.registry.Registerable; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.util.FileThread; +import com.minecrafttas.tasmod.events.EventKillTheRNGServer; import kaptainwutax.seedutils.lcg.LCG; import kaptainwutax.seedutils.rand.JRand; -public class RandomBase extends Random { - - private String name; - private String description; +public abstract class RandomBase extends Random implements Registerable { + RNGSide side; private long initialSeed; - public static FileThread writerThread; + private JRand jrand; - private JRand.Debugger jrand; + public RandomBase() { + super(TASmod.globalRandomness.getCurrentSeed()); + } public RandomBase(long seed) { super(seed); this.initialSeed = seed; - jrand = new JRand(seed, false).asDebugger(); + jrand = new JRand(seed, false); } @Override @@ -145,53 +145,25 @@ public String toString() { return Long.toString(getSeed()); } - @Override - public boolean equals(Object obj) { - if (obj instanceof RandomBase) { - RandomBase custom = (RandomBase) obj; - return custom.name.equals(name); - } else { - return super.equals(obj); - } - } - public void fireSetEvent(String eventType, long seed, String value, int stackTraceOffset) { -// fireEvent(eventType, seed, value, stackTraceOffset); + fireRNGEvent(eventType, seed, value, stackTraceOffset); } public void fireGetEvent(String eventType, long seed, String value) { -// fireEvent(eventType, seed, value, 3); + fireRNGEvent(eventType, seed, value, 3); } - public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { - if (!TASmod.debugRand.isActive()) { - return; - } + public long getInitialSeed() { + return initialSeed; + } + public void fireRNGEvent(String eventType, long seed, String value, int stackTraceOffset) { StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); - List classOut = new ArrayList<>(); - for (int i = stackTraceOffset; i < stackTraceOffset + 4; i++) { - String out = formatStackTraceElement(stackTraceElements[i]); - if (out != null) - classOut.add(out); - } - String out = String.format("%s %s %s\t%s\t%s", eventType, seed, value, this.getClass().getSimpleName(), String.join(", ", classOut)); - TASmod.debugRand.writeDebug(out); - } - - private String formatStackTraceElement(StackTraceElement stackTraceElement) { - String methodName = stackTraceElement.getMethodName(); - String[] classNames = stackTraceElement.getClassName().split("\\."); - String className = classNames[classNames.length - 1]; - if (methodName.equals("showBarrierParticles")) - return null; - String classOut = className + "." + methodName + - (stackTraceElement.isNativeMethod() ? "(Native Method)" : (stackTraceElement.getFileName() != null && stackTraceElement.getLineNumber() >= 0 ? "(" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() - + ")" : (stackTraceElement.getFileName() != null ? "(" + stackTraceElement.getFileName() + ")" : "(Unknown Source)"))); - return classOut; + EventListenerRegistry.fireEvent(EventKillTheRNGServer.EventRNG.class, side, eventType, seed, value, stackTraceElements); } - public long getInitialSeed() { - return initialSeed; + public enum RNGSide { + Server, + Client } } diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java deleted file mode 100644 index 28a52d49..00000000 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldRandomness.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.minecrafttas.tasmod.ktrng; - -import com.minecrafttas.tasmod.TASmod; - -public class WorldRandomness extends RandomBase { - - public WorldRandomness(long seed) { - super(seed); - } - - public WorldRandomness() { - super(TASmod.globalRandomness.getCurrentSeed()); - } - - @Override - public void fireEvent(String val, long seed, String value, int offset) { - super.fireEvent(val, seed, value, 5); - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java deleted file mode 100644 index e993f674..00000000 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/WorldSeedRandomness.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.minecrafttas.tasmod.ktrng; - -public class WorldSeedRandomness extends RandomBase { - - public WorldSeedRandomness(long seed) { - super(seed); - } - - @Override - public void fireEvent(String eventType, long seed, String value, int stackTraceOffset) { - } -} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/EntityRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/EntityRandomness.java new file mode 100644 index 00000000..81eddf81 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/EntityRandomness.java @@ -0,0 +1,24 @@ +package com.minecrafttas.tasmod.ktrng.builtin; + +import com.minecrafttas.tasmod.ktrng.RandomBase; + +public class EntityRandomness extends RandomBase { + + public EntityRandomness() { + super(); + } + + public EntityRandomness(long seed) { + super(seed); + } + + @Override + public void fireRNGEvent(String eventType, long seed, String value, int stackTraceOffset) { +// super.fireEvent(eventType, seed, value, stackTraceOffset); + } + + @Override + public String getExtensionName() { + return "EntityRNG"; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/MathRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/MathRandomness.java new file mode 100644 index 00000000..c2d5a878 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/MathRandomness.java @@ -0,0 +1,29 @@ +package com.minecrafttas.tasmod.ktrng.builtin; + +import com.minecrafttas.tasmod.ktrng.RandomBase; + +/** + *

Randomness instance for hooking into {@link Math#random()} + * + * @author Scribble + */ +public class MathRandomness extends RandomBase { + + public MathRandomness() { + super(); + } + + public MathRandomness(long seed) { + super(seed); + } + + @Override + public void fireRNGEvent(String eventType, long seed, String value, int stackTraceOffset) { +// super.fireEvent(eventType, seed, value, 6); + } + + @Override + public String getExtensionName() { + return "MathRNG"; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldRandomness.java new file mode 100644 index 00000000..db66efa8 --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldRandomness.java @@ -0,0 +1,24 @@ +package com.minecrafttas.tasmod.ktrng.builtin; + +import com.minecrafttas.tasmod.ktrng.RandomBase; + +public class WorldRandomness extends RandomBase { + + public WorldRandomness() { + super(); + } + + public WorldRandomness(long seed) { + super(seed); + } + + @Override + public void fireRNGEvent(String val, long seed, String value, int offset) { + super.fireRNGEvent(val, seed, value, 5); + } + + @Override + public String getExtensionName() { + return "WorldRNG"; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldSeedRandomness.java b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldSeedRandomness.java new file mode 100644 index 00000000..be7a6dcc --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/builtin/WorldSeedRandomness.java @@ -0,0 +1,23 @@ +package com.minecrafttas.tasmod.ktrng.builtin; + +import com.minecrafttas.tasmod.ktrng.RandomBase; + +public class WorldSeedRandomness extends RandomBase { + + public WorldSeedRandomness() { + super(); + } + + public WorldSeedRandomness(long seed) { + super(seed); + } + + @Override + public void fireRNGEvent(String eventType, long seed, String value, int stackTraceOffset) { + } + + @Override + public String getExtensionName() { + return "WorldSeedRNG"; + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/events/KillTheRNGMonitor.java b/src/main/java/com/minecrafttas/tasmod/ktrng/events/KillTheRNGMonitor.java new file mode 100644 index 00000000..f4b0752a --- /dev/null +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/events/KillTheRNGMonitor.java @@ -0,0 +1,32 @@ +package com.minecrafttas.tasmod.ktrng.events; + +import com.minecrafttas.mctcommon.events.EventServer; +import com.minecrafttas.tasmod.events.EventKillTheRNGServer; +import com.minecrafttas.tasmod.events.EventPlaybackServer; +import com.minecrafttas.tasmod.ktrng.RandomBase.RNGSide; +import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; + +import net.minecraft.server.MinecraftServer; + +public class KillTheRNGMonitor implements EventPlaybackServer.EventControllerStateChange, EventPlaybackServer.EventRecordClear, EventServer.EventServerTick, EventKillTheRNGServer.EventRNG { + + @Override + public void onServerTick(MinecraftServer server) { + + } + + @Override + public void onControllerStateChange(TASstate newstate, TASstate oldstate) { + + } + + @Override + public void onRecordingClear() { + + } + + @Override + public void onRNGCall(RNGSide side, String eventType, long seed, String value, StackTraceElement[] stackTraceElements) { + + } +} diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGEntityHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/handlers/KTRNGEntityHandler.java similarity index 90% rename from src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGEntityHandler.java rename to src/main/java/com/minecrafttas/tasmod/ktrng/handlers/KTRNGEntityHandler.java index 62da4da6..db66af07 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGEntityHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/handlers/KTRNGEntityHandler.java @@ -1,10 +1,11 @@ -package com.minecrafttas.tasmod.ktrng; +package com.minecrafttas.tasmod.ktrng.handlers; import java.util.HashMap; import java.util.Map; import java.util.UUID; import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.ktrng.builtin.EntityRandomness; import net.minecraft.entity.Entity; import net.minecraft.world.WorldServer; diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java b/src/main/java/com/minecrafttas/tasmod/ktrng/handlers/KTRNGWorldHandler.java similarity index 94% rename from src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java rename to src/main/java/com/minecrafttas/tasmod/ktrng/handlers/KTRNGWorldHandler.java index d1c66971..0136aeee 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KTRNGWorldHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/handlers/KTRNGWorldHandler.java @@ -1,9 +1,10 @@ -package com.minecrafttas.tasmod.ktrng; +package com.minecrafttas.tasmod.ktrng.handlers; import java.util.HashMap; import java.util.Map; import com.minecrafttas.tasmod.TASmod; +import com.minecrafttas.tasmod.ktrng.builtin.WorldRandomness; import net.minecraft.world.WorldServer; diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java index 3bef0312..6db86d40 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinEntity.java @@ -9,7 +9,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.minecrafttas.tasmod.ktrng.EntityRandomness; +import com.minecrafttas.tasmod.ktrng.builtin.EntityRandomness; import net.minecraft.entity.Entity; import net.minecraft.world.World; @@ -21,9 +21,8 @@ public class MixinEntity { public Random modify_entityRandom(Random original, World world) { if (!world.isRemote) { return new EntityRandomness(); - } else { - return new EntityRandomness(0L); } + return original; } @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;getRandomUUID(Ljava/util/Random;)Ljava/util/UUID;")) diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java index a783c2d1..9e50b82c 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/MixinWorld.java @@ -9,7 +9,7 @@ import com.llamalad7.mixinextras.injector.ModifyReceiver; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.ktrng.WorldRandomness; +import com.minecrafttas.tasmod.ktrng.builtin.WorldRandomness; import net.minecraft.world.World; import net.minecraft.world.WorldServer; diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java index e4c718ca..3d9223da 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinWorldEntitySpawner.java @@ -5,7 +5,6 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.minecrafttas.tasmod.TASmod; import net.minecraft.world.WorldEntitySpawner; import net.minecraft.world.WorldServer; @@ -15,6 +14,6 @@ public class MixinWorldEntitySpawner { @WrapOperation(method = "findChunksForSpawning", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) private double wrap_worldEntitySpawnerFindChunks(Operation original, WorldServer worldServer, boolean bl, boolean bl2, boolean bl3) { - return TASmod.mathRandomness.nextDouble(); + return worldServer.rand.nextDouble(); } } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/files/SavestateDataFile.java b/src/main/java/com/minecrafttas/tasmod/savestates/files/SavestateDataFile.java index 86be2b42..faabe05e 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/files/SavestateDataFile.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/files/SavestateDataFile.java @@ -7,13 +7,18 @@ @Deprecated public class SavestateDataFile extends AbstractDataFile { + @Deprecated public SavestateDataFile(Path file) { super(file, "savestatedata", "Data for this savestate from TASmod"); } + @Deprecated public enum DataValues { + @Deprecated INDEX("currentIndex"), + @Deprecated NAME("savestateName"), + @Deprecated SEED("ktrngSeed"); private String configname; @@ -22,15 +27,18 @@ private DataValues(String configname) { this.configname = configname; } + @Deprecated public String getConfigName() { return configname; } } + @Deprecated public void set(DataValues key, String val) { properties.setProperty(key.getConfigName(), val); } + @Deprecated public String get(DataValues key) { return properties.getProperty(key.getConfigName()); } diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java index 086e74cd..cdab59a6 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/SavestateStorageExtensionRegistry.java @@ -52,7 +52,7 @@ public void onServerSavestate(MinecraftServer server, SavestatePaths paths) { private void load(SavestatePaths paths) { jsonMap.clear(); - Path storageDir = paths.getTargetFolder().resolve(SavestateIndexer.savestateDataDir); + Path storageDir = paths.getSourceFolder().resolve(SavestateIndexer.savestateDataDir); if (!Files.exists(storageDir)) { try { Files.createDirectory(storageDir); diff --git a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java index 4a2324a5..8d332aaf 100644 --- a/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java +++ b/src/main/java/com/minecrafttas/tasmod/savestates/storage/builtin/KTRNGSeedStorage.java @@ -8,10 +8,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.minecrafttas.tasmod.TASmod; -import com.minecrafttas.tasmod.ktrng.EntityRandomness; -import com.minecrafttas.tasmod.ktrng.KTRNGEntityHandler; -import com.minecrafttas.tasmod.ktrng.KTRNGWorldHandler; -import com.minecrafttas.tasmod.ktrng.WorldRandomness; +import com.minecrafttas.tasmod.ktrng.builtin.EntityRandomness; +import com.minecrafttas.tasmod.ktrng.builtin.WorldRandomness; +import com.minecrafttas.tasmod.ktrng.handlers.KTRNGEntityHandler; +import com.minecrafttas.tasmod.ktrng.handlers.KTRNGWorldHandler; import com.minecrafttas.tasmod.savestates.storage.SavestateStorageExtensionBase; import net.minecraft.server.MinecraftServer; @@ -59,7 +59,7 @@ public JsonObject onSavestate(MinecraftServer server, JsonObject dataToSave) { dataToSave.add("worldRandom", worldRandomDataJson); - dataToSave.addProperty("mathRandom", Long.toString(TASmod.mathRandomness.getSeed())); + dataToSave.addProperty("mathRandom", TASmod.mathRandomness.getSeed()); return dataToSave; } @@ -106,7 +106,8 @@ public void onLoadstateComplete(MinecraftServer server, JsonObject loadedData) { KTRNGWorldHandler.setWorldRandomnessMap(worldList); - TASmod.mathRandomness.setSeed(loadedData.get("mathRandom").getAsLong()); + long mathSeed = loadedData.get("mathRandom").getAsLong(); + TASmod.mathRandomness.setSeed(mathSeed); } @Override diff --git a/src/test/java/tasmod/killtherng/RNGTest.java b/src/test/java/tasmod/killtherng/RNGTest.java index b969345e..296524e4 100644 --- a/src/test/java/tasmod/killtherng/RNGTest.java +++ b/src/test/java/tasmod/killtherng/RNGTest.java @@ -7,8 +7,9 @@ public class RNGTest { public static void main(String[] args) { long[] longlist = new long[] { //@formatter:off - 113621727298730L, - 161845404674820L + 221103401599600L, + 145180429625787L, + 179651266561706L //@formatter:on }; diff --git a/src/test/java/tasmod/killtherng/RandomBaseTest.java b/src/test/java/tasmod/killtherng/RandomBaseTest.java index 38f0966c..1845241f 100644 --- a/src/test/java/tasmod/killtherng/RandomBaseTest.java +++ b/src/test/java/tasmod/killtherng/RandomBaseTest.java @@ -9,7 +9,24 @@ import kaptainwutax.seedutils.rand.JRand; -class RandomBaseTest { +class TestRNGTest { + + class TestRNG extends RandomBase { + + public TestRNG() { + super(); + } + + public TestRNG(long seed) { + super(seed); + } + + @Override + public String getExtensionName() { + return "TestRNG"; + } + + } @BeforeEach void setUp() throws Exception { @@ -18,14 +35,14 @@ void setUp() throws Exception { @Test void testInitialSeed() { long expected = 12345L; - RandomBase testRandom = new RandomBase(expected); + TestRNG testRandom = new TestRNG(expected); long actual = testRandom.getSeed(); assertEquals(12345L, actual); } @Test void testSetSeed() { - RandomBase testRandom = new RandomBase(1L); + TestRNG testRandom = new TestRNG(1L); testRandom.setSeed(12345L); assertEquals(12345L, testRandom.getSeed()); } @@ -33,7 +50,7 @@ void testSetSeed() { @Test void testAdvance() { JRand thing = JRand.ofInternalSeed(12345L); - RandomBase testRandom = new RandomBase(12345L); + TestRNG testRandom = new TestRNG(12345L); testRandom.advance(); thing.advance(1); @@ -44,7 +61,7 @@ void testAdvance() { @Test void testAdvancingLong() { JRand thing = JRand.ofInternalSeed(12345L); - RandomBase testRandom = new RandomBase(12345L); + TestRNG testRandom = new TestRNG(12345L); long expectedValue = thing.nextLong(); long actualValue = testRandom.nextLong(); @@ -56,7 +73,7 @@ void testAdvancingLong() { @Test void testAdvancingLong2() { JRand thing = JRand.ofInternalSeed(12345L); - RandomBase testRandom = new RandomBase(12345L); + TestRNG testRandom = new TestRNG(12345L); testRandom.nextLong(); thing.advance(2); @@ -66,8 +83,8 @@ void testAdvancingLong2() { @Test void testAdvancingDifferentRNGs() { - RandomBase testRandom1 = new RandomBase(12345L); - RandomBase testRandom2 = new RandomBase(12345L); + TestRNG testRandom1 = new TestRNG(12345L); + TestRNG testRandom2 = new TestRNG(12345L); testRandom1.nextInt(); testRandom2.nextInt(6); From 65cd6c5531bec3288475040e7e910c9b4a09a8a5 Mon Sep 17 00:00:00 2001 From: Scribble Date: Mon, 16 Mar 2026 22:08:18 +0100 Subject: [PATCH 25/26] [KillTheRNG] Fix nextFloat and nextGaussian not firing events --- .../java/com/minecrafttas/tasmod/ktrng/RandomBase.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index c75f9f9e..41af805a 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -106,13 +106,17 @@ public int nextInt(int bound) { @Override public float nextFloat() { - return jrand.nextFloat(); + long seedstored = getSeed(); + float value = jrand.nextFloat(); + fireGetEvent("nextFloat", seedstored, Float.toString(value)); + return value; } @Override public double nextGaussian() { - double value = 0; - value = jrand.nextGaussian(); + long seedstored = getSeed(); + double value = jrand.nextGaussian(); + fireGetEvent("nextGaussian", seedstored, Double.toString(value)); return value; } From 52775bf85fe965cb554ce8cc6efca6fb1009fd60 Mon Sep 17 00:00:00 2001 From: Scribble Date: Thu, 19 Mar 2026 21:32:26 +0100 Subject: [PATCH 26/26] [KillTheRNG] Crash fixes --- src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java | 6 +----- .../mixin/killtherng/mathrand/MixinEntityTNTPrimed.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java index 41af805a..ffc7a485 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/RandomBase.java @@ -18,6 +18,7 @@ public abstract class RandomBase extends Random implements Registerable { public RandomBase() { super(TASmod.globalRandomness.getCurrentSeed()); + jrand = new JRand(TASmod.globalRandomness.getCurrentSeed()); } public RandomBase(long seed) { @@ -61,7 +62,6 @@ public long getSeed() { @Override public long nextLong() { -// timesCalled++; long seedstored = getSeed(); long value = jrand.nextLong(); fireGetEvent("nextLong()", seedstored, Long.toString(value)); @@ -70,7 +70,6 @@ public long nextLong() { @Override public double nextDouble() { -// timesCalled++; long seedstored = getSeed(); double value = jrand.nextDouble(); fireGetEvent("nextDouble()", seedstored, Double.toString(value)); @@ -79,7 +78,6 @@ public double nextDouble() { @Override public boolean nextBoolean() { -// timesCalled++; long seedstored = getSeed(); boolean value = jrand.nextBoolean(); fireGetEvent("nextBoolean()", seedstored, Boolean.toString(value)); @@ -88,7 +86,6 @@ public boolean nextBoolean() { @Override public int nextInt() { -// timesCalled++; long seedstored = getSeed(); int value = jrand.nextInt(); fireGetEvent("nextInt()", seedstored, Integer.toString(value)); @@ -97,7 +94,6 @@ public int nextInt() { @Override public int nextInt(int bound) { -// timesCalled++; long seedstored = getSeed(); int value = jrand.nextInt(bound); fireGetEvent(String.format("nextInt(%s)", bound), seedstored, Integer.toString(value)); diff --git a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java index bd8fec2d..add0e4e1 100644 --- a/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java +++ b/src/main/java/com/minecrafttas/tasmod/mixin/killtherng/mathrand/MixinEntityTNTPrimed.java @@ -14,7 +14,7 @@ @Mixin(EntityTNTPrimed.class) public class MixinEntityTNTPrimed { - @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) + @WrapOperation(method = "(Lnet/minecraft/world/World;DDDLnet/minecraft/entity/EntityLivingBase;)V", at = @At(value = "INVOKE", target = "Ljava/lang/Math;random()D")) private double wrap_entityTNTPrimedInit(Operation original, World world, double d, double e, double f, EntityLivingBase entityLivingBase) { return TASmod.mathRandomness.nextDouble(); }