Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master-1.19-lts' into master-1.2…
Browse files Browse the repository at this point in the history
…0-lts
  • Loading branch information
rubensworks committed Dec 13, 2024
2 parents 89f5400 + 1cdcfa8 commit 9a25342
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions resources/changelog/1.19.2-1.19.6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
As always, don't forget to backup your world before updating!

Fixes:
* Fix rare RandomSource cross-thread crash

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.cyclops.cyclopscore.helper;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.fml.DistExecutor;

import javax.annotation.Nullable;
Expand All @@ -21,6 +22,8 @@ public class WorldHelpers {

private static final double TICK_LAG_REDUCTION_MODULUS_MODIFIER = 1.0D;

private static final RandomSource RANDOM = RandomSource.create();

/**
* Check if an efficient tick can happen.
* This is useful for opererations that should happen frequently, but not strictly every tick.
Expand All @@ -34,7 +37,7 @@ public static boolean efficientTick(Level world, int baseModulus, int... params)
if(mod == 0) mod = 1;
int offset = 0;
for(int param : params) offset += param;
return world.random.nextInt(mod) == Math.abs(offset) % mod;
return RANDOM.nextInt(mod) == Math.abs(offset) % mod;
}

/**
Expand Down

0 comments on commit 9a25342

Please sign in to comment.