From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Wed, 23 Nov 2022 22:49:59 +0100 Subject: [PATCH] Use ThreadUnsafeRandom for mob spawning Removed since 1.21 License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) Gale - https://galemc.org This patch is based on the following patch: "Use thread unsafe random for mob spawning" By: Paul Sauve As part of: Airplane (https://github.com/TECHNOVE/Airplane) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) * Airplane copyright * Airplane Copyright (C) 2020 Technove LLC This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/src/main/java/net/minecraft/world/level/NaturalSpawner.java b/src/main/java/net/minecraft/world/level/NaturalSpawner.java index 7e707fe1d800debf1eef8800fe98eb4e1dbd800b..d0383cef6e204cc806903666d296287e1c530ed3 100644 --- a/src/main/java/net/minecraft/world/level/NaturalSpawner.java +++ b/src/main/java/net/minecraft/world/level/NaturalSpawner.java @@ -406,13 +406,14 @@ public final class NaturalSpawner { } } - private static BlockPos getRandomPosWithin(Level world, LevelChunk chunk) { + private static BlockPos getRandomPosWithin(ServerLevel world, LevelChunk chunk) { // Gale - Airplane - Use ThreadUnsafeRandom for mob spawning - accept ServerLevel ChunkPos chunkcoordintpair = chunk.getPos(); - int i = chunkcoordintpair.getMinBlockX() + world.random.nextInt(16); - int j = chunkcoordintpair.getMinBlockZ() + world.random.nextInt(16); + // Gale start - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom + int i = chunkcoordintpair.getMinBlockX() + world.randomTickRandom.nextInt(16); + int j = chunkcoordintpair.getMinBlockZ() + world.randomTickRandom.nextInt(16); + // Gale end - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom int k = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i, j) + 1; - int l = Mth.randomBetweenInclusive(world.random, world.getMinBuildHeight(), k); - + int l = Mth.randomBetweenInclusive(world.randomTickRandom, world.getMinBuildHeight(), k); // Gale - Airplane - Use ThreadUnsafeRandom for mob spawning - use ThreadUnsafeRandom return new BlockPos(i, l, j); }