diff --git a/src/main/java/ru/bclib/blocks/BaseCropBlock.java b/src/main/java/ru/bclib/blocks/BaseCropBlock.java index 2a5cf863..4e99cb1d 100644 --- a/src/main/java/ru/bclib/blocks/BaseCropBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCropBlock.java @@ -78,13 +78,13 @@ public class BaseCropBlock extends BasePlantBlock { if (tool != null && tool.isCorrectToolForDrops(state)) { int enchantment = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool); if (enchantment > 0) { - int countSeeds = MHelper.randRange(Mth.clamp(1 + enchantment, 1, 3), 3, MHelper.RANDOM); - int countDrops = MHelper.randRange(Mth.clamp(1 + enchantment, 1, 2), 2, MHelper.RANDOM); + int countSeeds = MHelper.randRange(Mth.clamp(1 + enchantment, 1, 3), 3, MHelper.RANDOM_SOURCE); + int countDrops = MHelper.randRange(Mth.clamp(1 + enchantment, 1, 2), 2, MHelper.RANDOM_SOURCE); return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops)); } } - int countSeeds = MHelper.randRange(1, 3, MHelper.RANDOM); - int countDrops = MHelper.randRange(1, 2, MHelper.RANDOM); + int countSeeds = MHelper.randRange(1, 3, MHelper.RANDOM_SOURCE); + int countDrops = MHelper.randRange(1, 2, MHelper.RANDOM_SOURCE); return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops)); } diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index eca1b733..2bd04a12 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -89,9 +89,9 @@ public class BaseOreBlock extends DropExperienceBlock implements BlockModelProvi if (min == max) { return Collections.singletonList(new ItemStack(dropItem, max)); } - count = MHelper.randRange(min, max, MHelper.RANDOM); + count = MHelper.randRange(min, max, MHelper.RANDOM_SOURCE); } else { - count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM); + count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM_SOURCE); } return Collections.singletonList(new ItemStack(dropItem, count)); } diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index 8d34db3e..8d6139f3 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -39,37 +39,52 @@ import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Optional; -import java.util.Random;import net.minecraft.util.RandomSource; +import java.util.Random; +import java.util.function.Function; + +import net.minecraft.util.RandomSource; public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock{ private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public BasePlantBlock() { - this(false); + this(false, p->p); } - + public BasePlantBlock(int light) { - this(false, light); + this(light, p->p); } - public BasePlantBlock(boolean replaceable) { + public BasePlantBlock(int light, Function propMod) { + this(false, light, propMod); + } + + public BasePlantBlock(boolean replaceabled) { + this(replaceabled, p->p); + } + public BasePlantBlock(boolean replaceable, Function propMod) { this( - FabricBlockSettings + propMod.apply(FabricBlockSettings .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) .sound(SoundType.GRASS) .noCollission() .offsetType(BlockBehaviour.OffsetType.XZ) + ) ); } - - public BasePlantBlock(boolean replaceable, int light) { + + public BasePlantBlock(boolean replaceable, int light){ + this(replaceable, light, p->p); + } + public BasePlantBlock(boolean replaceable, int light, Function propMod) { this( - FabricBlockSettings + propMod.apply(FabricBlockSettings .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) .luminance(light) .sound(SoundType.GRASS) .noCollission() .offsetType(BlockBehaviour.OffsetType.XZ) + ) ); } diff --git a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java index 4c8b148d..22f14454 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java @@ -12,18 +12,26 @@ import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.material.Material; -import java.util.Random;import net.minecraft.util.RandomSource; +import java.util.Properties; +import java.util.Random; +import java.util.function.Function; + +import net.minecraft.util.RandomSource; public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public static final IntegerProperty AGE = BlockProperties.AGE; public BasePlantWithAgeBlock() { + this(p->p); + } + + public BasePlantWithAgeBlock(Function propMod) { this( - FabricBlockSettings.of(Material.PLANT) - .sound(SoundType.GRASS) - .randomTicks() - .noCollission() - ); + propMod.apply(FabricBlockSettings.of(Material.PLANT) + .sound(SoundType.GRASS) + .randomTicks() + .noCollission()) + ); } public BasePlantWithAgeBlock(Properties settings) { diff --git a/src/main/java/ru/bclib/blocks/BaseVineBlock.java b/src/main/java/ru/bclib/blocks/BaseVineBlock.java index 3919f24e..ff830008 100644 --- a/src/main/java/ru/bclib/blocks/BaseVineBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseVineBlock.java @@ -34,7 +34,10 @@ import ru.bclib.items.tool.BaseShearsItem; import ru.bclib.util.BlocksHelper; import java.util.List; -import java.util.Random;import net.minecraft.util.RandomSource; +import java.util.Random; +import java.util.function.Function; + +import net.minecraft.util.RandomSource; @SuppressWarnings("deprecation") public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { @@ -48,15 +51,18 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid public BaseVineBlock(int light) { this(light, false); } - - public BaseVineBlock(int light, boolean bottomOnly) { + + public BaseVineBlock(int light, boolean bottomOnly){ + this(light, bottomOnly, p->p); + } + public BaseVineBlock(int light, boolean bottomOnly, Function propMod) { this( - FabricBlockSettings + propMod.apply(FabricBlockSettings .of(Material.PLANT) .sound(SoundType.GRASS) .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) .noCollission() - .offsetType(BlockBehaviour.OffsetType.XZ) + .offsetType(BlockBehaviour.OffsetType.XZ)) ); } diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index 6fdc9bfb..00b87105 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -35,29 +35,37 @@ import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.items.tool.BaseShearsItem; import java.util.List; -import java.util.Random;import net.minecraft.util.RandomSource; +import java.util.Random; +import java.util.function.Function; + +import net.minecraft.util.RandomSource; public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); - - public UnderwaterPlantBlock() { + + public UnderwaterPlantBlock(){this(p->p);} + public UnderwaterPlantBlock(Function propMod) { this( - FabricBlockSettings + propMod.apply(FabricBlockSettings .of(Material.WATER_PLANT) .sound(SoundType.WET_GRASS) .noCollission() - .offsetType(BlockBehaviour.OffsetType.XZ) + .offsetType(BlockBehaviour.OffsetType.XZ)) ); } - + public UnderwaterPlantBlock(int light) { + this(light, p->p); + } + + public UnderwaterPlantBlock(int light, Function propMod) { this( - FabricBlockSettings + propMod.apply(FabricBlockSettings .of(Material.WATER_PLANT) .luminance(light) .sound(SoundType.WET_GRASS) .noCollission() - .offsetType(BlockBehaviour.OffsetType.XZ) + .offsetType(BlockBehaviour.OffsetType.XZ)) ); } diff --git a/src/main/java/ru/bclib/util/BlocksHelper.java b/src/main/java/ru/bclib/util/BlocksHelper.java index 766280f2..042d8102 100644 --- a/src/main/java/ru/bclib/util/BlocksHelper.java +++ b/src/main/java/ru/bclib/util/BlocksHelper.java @@ -150,7 +150,7 @@ public class BlocksHelper { * @param random - {@link Random}. * @return {@link Direction}. */ - public static Direction randomHorizontal(Random random) { + public static Direction randomHorizontal(RandomSource random) { return HORIZONTAL[random.nextInt(4)]; } @@ -160,7 +160,7 @@ public class BlocksHelper { * @param random - {@link Random}. * @return {@link Direction}. */ - public static Direction randomDirection(Random random) { + public static Direction randomDirection(RandomSource random) { return DIRECTIONS[random.nextInt(6)]; } diff --git a/src/main/java/ru/bclib/util/MHelper.java b/src/main/java/ru/bclib/util/MHelper.java index e661b0b6..732bb987 100644 --- a/src/main/java/ru/bclib/util/MHelper.java +++ b/src/main/java/ru/bclib/util/MHelper.java @@ -4,6 +4,7 @@ import com.mojang.math.Vector3f; import net.minecraft.core.Vec3i; import java.util.Random;import net.minecraft.util.RandomSource; +import net.minecraft.world.level.levelgen.LegacyRandomSource; public class MHelper { private static final Vec3i[] RANDOM_OFFSETS = new Vec3i[3 * 3 * 3 - 1]; @@ -11,16 +12,17 @@ public class MHelper { public static final float PHI = (float) (Math.PI * (3 - Math.sqrt(5))); public static final float PI2 = (float) (Math.PI * 2); public static final Random RANDOM = new Random(); + public static final RandomSource RANDOM_SOURCE = new LegacyRandomSource(RANDOM.nextLong()); - public static int randRange(int min, int max, Random random) { + public static int randRange(int min, int max, RandomSource random) { return min + random.nextInt(max - min + 1); } - public static double randRange(double min, double max, Random random) { + public static double randRange(double min, double max, RandomSource random) { return min + random.nextDouble() * (max - min); } - public static float randRange(float min, float max, Random random) { + public static float randRange(float min, float max, RandomSource random) { return min + random.nextFloat() * (max - min); } @@ -195,7 +197,7 @@ public class MHelper { return (float) Math.acos(dot / Math.sqrt(length1 * length2)); } - public static Vector3f randomHorizontal(Random random) { + public static Vector3f randomHorizontal(RandomSource random) { float angleY = randRange(0, PI2, random); float vx = (float) Math.sin(angleY); float vz = (float) Math.cos(angleY); diff --git a/src/main/java/ru/bclib/util/SplineHelper.java b/src/main/java/ru/bclib/util/SplineHelper.java index 2868bf46..680dac72 100644 --- a/src/main/java/ru/bclib/util/SplineHelper.java +++ b/src/main/java/ru/bclib/util/SplineHelper.java @@ -55,7 +55,7 @@ public class SplineHelper { return new Vector3f(x, y, z); } - public static void offsetParts(List spline, Random random, float dx, float dy, float dz) { + public static void offsetParts(List spline, RandomSource random, float dx, float dy, float dz) { int count = spline.size(); for (int i = 1; i < count; i++) { Vector3f pos = spline.get(i); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 8d481e1c..cfbb27ea 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -130,6 +130,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { @Override public void setSeed(long seed) { + if (seed==currentSeed) return; super.setSeed(seed); biomePicker.rebuild(); initMap(seed); diff --git a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceNoiseCondition.java b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceNoiseCondition.java index 59e1d4b5..73e2000b 100644 --- a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceNoiseCondition.java +++ b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceNoiseCondition.java @@ -34,7 +34,7 @@ public class DoubleBlockSurfaceNoiseCondition extends SurfaceNoiseCondition { final int z = context.getBlockZ(); if (lastX==x && lastZ==z) return lastValue > threshold; - double value = NOISE.eval(x * 0.1, z * 0.1) + MHelper.randRange(-0.4, 0.4, MHelper.RANDOM); + double value = NOISE.eval(x * 0.1, z * 0.1) + MHelper.randRange(-0.4, 0.4, MHelper.RANDOM_SOURCE); lastX=x; lastZ=z;