From 32afd73ac874e3b95c13c38fdf3ca94a04196d37 Mon Sep 17 00:00:00 2001 From: ah-OOG-ah <75745146+ah-OOG-ah@users.noreply.github.com> Date: Sat, 30 May 2026 13:53:32 -0400 Subject: [PATCH] Fix position hash for random models (#381) --- .../gtnhlib/client/model/ModelISBRH.java | 3 +-- .../gtnhlib/client/model/WorldContext.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/model/ModelISBRH.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/ModelISBRH.java index c94df91b..430d6000 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/client/model/ModelISBRH.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/ModelISBRH.java @@ -5,7 +5,6 @@ import static com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8.unpac import static com.gtnewhorizon.gtnhlib.client.renderer.cel.api.util.NormI8.unpackZ; import static com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing.DIRECTIONS; import static com.gtnewhorizon.gtnhlib.client.renderer.cel.model.quad.properties.ModelQuadFacing.VALUES; -import static com.gtnewhorizon.gtnhlib.util.CoordinatePacker.pack; import static java.lang.Float.intBitsToFloat; import static java.lang.Math.max; import static net.minecraftforge.client.IItemRenderer.ItemRenderType.ENTITY; @@ -83,7 +82,7 @@ public class ModelISBRH implements ISimpleBlockRenderingHandler, IItemRenderer { var rendered = false; for (var dir : VALUES) { worldContext.quadFacing = dir; - worldContext.random.setSeed(pack(x, y, z)); + worldContext.seedRNG(x, y, z); final var quads = model.getQuads(worldContext); if (quads.isEmpty()) continue; diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/client/model/WorldContext.java b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/WorldContext.java index 829b0362..ee1da246 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/client/model/WorldContext.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/client/model/WorldContext.java @@ -1,7 +1,5 @@ package com.gtnewhorizon.gtnhlib.client.model; -import static com.gtnewhorizon.gtnhlib.util.CoordinatePacker.pack; - import java.util.Random; import java.util.function.Supplier; @@ -39,7 +37,14 @@ public class WorldContext implements BakedModelQuadContext.World { this.z = z; this.blockState = BlockPropertyRegistry.getBlockState(world, x, y, z); this.random = random; - random.setSeed(pack(x, y, z)); + seedRNG(x, y, z); + } + + /// Don't ask me why the magic numbers work, because I don't know. Something something hash function... + public void seedRNG(int x, int y, int z) { + long h = x * 3129871L ^ y * 116129781L ^ z; + h = h * h * 42317861L + h * 11L; + random.setSeed(h ^ (h >>> 16)); } @Override @@ -81,4 +86,5 @@ public class WorldContext implements BakedModelQuadContext.World { public @Nullable Supplier getQuadPool() { return quadPool; } + }