From bfdb26ac2274fb232f0295f243aafa0fc8a206c0 Mon Sep 17 00:00:00 2001 From: Scribble Date: Sat, 6 Jan 2024 13:42:33 +0100 Subject: [PATCH] [KillTheRNG] Added random seed display above entities --- .../killtherng/mixin/MixinRender.java | 35 +++++++++++++++++++ .../tasmod/ktrng/KillTheRNGHandler.java | 11 +++--- src/main/resources/fabric.mod.json | 4 ++- src/main/resources/killtherng.mixin.json | 13 +++++++ src/main/resources/tasmod.accesswidener | 3 ++ 5 files changed, 59 insertions(+), 7 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 66d8533b..023bc62b 100644 --- a/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java +++ b/src/main/java/com/minecrafttas/tasmod/ktrng/KillTheRNGHandler.java @@ -41,15 +41,14 @@ public class KillTheRNGHandler implements EventServerTick, EventPlayerJoinedClie * @param isLoaded If the KillTheRNG mod is loaded */ public KillTheRNGHandler(boolean isLoaded) { - this.isLoaded = isLoaded; if (isLoaded) { - KillTheRNG.LOGGER.info("Connection established with TASmod"); - KillTheRNG.isLibrary = true; - KillTheRNG.mode = SeedingModes.TickChange; - - KillTheRNG.annotations.register(new KTRNGMonitor()); +// KillTheRNG.LOGGER.info("Connection established with TASmod"); +// KillTheRNG.isLibrary = true; +// KillTheRNG.mode = SeedingModes.TickChange; +// +// KillTheRNG.annotations.register(new KTRNGMonitor()); } else { LOGGER.info("KillTheRNG doesn't appear to be loaded"); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3b74370d..ddc270ae 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,7 +26,9 @@ ] }, "mixins": [ - "tasmod.mixin.json" + "mctcommon.mixin.json", + "tasmod.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 99c6bdf0..7098a6fb 100644 --- a/src/main/resources/tasmod.accesswidener +++ b/src/main/resources/tasmod.accesswidener @@ -14,3 +14,6 @@ accessible field net/minecraft/world/WorldServer pendingTickListEntriesHashSet L 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