Compile-Fixes in BetterEnd

This commit is contained in:
Frank 2022-05-17 18:09:43 +02:00
parent b6321cec93
commit a57845f96b
11 changed files with 82 additions and 42 deletions

View file

@ -78,13 +78,13 @@ public class BaseCropBlock extends BasePlantBlock {
if (tool != null && tool.isCorrectToolForDrops(state)) { if (tool != null && tool.isCorrectToolForDrops(state)) {
int enchantment = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool); int enchantment = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool);
if (enchantment > 0) { if (enchantment > 0) {
int countSeeds = MHelper.randRange(Mth.clamp(1 + enchantment, 1, 3), 3, 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); 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)); return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops));
} }
} }
int countSeeds = MHelper.randRange(1, 3, MHelper.RANDOM); int countSeeds = MHelper.randRange(1, 3, MHelper.RANDOM_SOURCE);
int countDrops = MHelper.randRange(1, 2, MHelper.RANDOM); int countDrops = MHelper.randRange(1, 2, MHelper.RANDOM_SOURCE);
return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops)); return Lists.newArrayList(new ItemStack(this, countSeeds), new ItemStack(drop, countDrops));
} }

View file

@ -89,9 +89,9 @@ public class BaseOreBlock extends DropExperienceBlock implements BlockModelProvi
if (min == max) { if (min == max) {
return Collections.singletonList(new ItemStack(dropItem, max)); return Collections.singletonList(new ItemStack(dropItem, max));
} }
count = MHelper.randRange(min, max, MHelper.RANDOM); count = MHelper.randRange(min, max, MHelper.RANDOM_SOURCE);
} else { } else {
count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM); count = MHelper.randRange(minCount, maxCount, MHelper.RANDOM_SOURCE);
} }
return Collections.singletonList(new ItemStack(dropItem, count)); return Collections.singletonList(new ItemStack(dropItem, count));
} }

View file

@ -39,37 +39,52 @@ import ru.bclib.items.tool.BaseShearsItem;
import java.util.List; import java.util.List;
import java.util.Optional; 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{ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock{
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public BasePlantBlock() { public BasePlantBlock() {
this(false); this(false, p->p);
} }
public BasePlantBlock(int light) { public BasePlantBlock(int light) {
this(false, light); this(light, p->p);
} }
public BasePlantBlock(boolean replaceable) { public BasePlantBlock(int light, Function<Properties, Properties> propMod) {
this(false, light, propMod);
}
public BasePlantBlock(boolean replaceabled) {
this(replaceabled, p->p);
}
public BasePlantBlock(boolean replaceable, Function<Properties, Properties> propMod) {
this( this(
FabricBlockSettings propMod.apply(FabricBlockSettings
.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.noCollission() .noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ) .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<Properties, Properties> propMod) {
this( this(
FabricBlockSettings propMod.apply(FabricBlockSettings
.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.luminance(light) .luminance(light)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.noCollission() .noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ) .offsetType(BlockBehaviour.OffsetType.XZ)
)
); );
} }

View file

@ -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.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.Material; 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 abstract class BasePlantWithAgeBlock extends BasePlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE; public static final IntegerProperty AGE = BlockProperties.AGE;
public BasePlantWithAgeBlock() { public BasePlantWithAgeBlock() {
this(p->p);
}
public BasePlantWithAgeBlock(Function<Properties, Properties> propMod) {
this( this(
FabricBlockSettings.of(Material.PLANT) propMod.apply(FabricBlockSettings.of(Material.PLANT)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.randomTicks() .randomTicks()
.noCollission() .noCollission())
); );
} }
public BasePlantWithAgeBlock(Properties settings) { public BasePlantWithAgeBlock(Properties settings) {

View file

@ -34,7 +34,10 @@ import ru.bclib.items.tool.BaseShearsItem;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import java.util.List; 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") @SuppressWarnings("deprecation")
public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock {
@ -48,15 +51,18 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid
public BaseVineBlock(int light) { public BaseVineBlock(int light) {
this(light, false); 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<Properties, Properties> propMod) {
this( this(
FabricBlockSettings propMod.apply(FabricBlockSettings
.of(Material.PLANT) .of(Material.PLANT)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light)
.noCollission() .noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ) .offsetType(BlockBehaviour.OffsetType.XZ))
); );
} }

View file

@ -35,29 +35,37 @@ import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.items.tool.BaseShearsItem; import ru.bclib.items.tool.BaseShearsItem;
import java.util.List; 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 { public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public UnderwaterPlantBlock() { public UnderwaterPlantBlock(){this(p->p);}
public UnderwaterPlantBlock(Function<Properties, Properties> propMod) {
this( this(
FabricBlockSettings propMod.apply(FabricBlockSettings
.of(Material.WATER_PLANT) .of(Material.WATER_PLANT)
.sound(SoundType.WET_GRASS) .sound(SoundType.WET_GRASS)
.noCollission() .noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ) .offsetType(BlockBehaviour.OffsetType.XZ))
); );
} }
public UnderwaterPlantBlock(int light) { public UnderwaterPlantBlock(int light) {
this(light, p->p);
}
public UnderwaterPlantBlock(int light, Function<Properties, Properties> propMod) {
this( this(
FabricBlockSettings propMod.apply(FabricBlockSettings
.of(Material.WATER_PLANT) .of(Material.WATER_PLANT)
.luminance(light) .luminance(light)
.sound(SoundType.WET_GRASS) .sound(SoundType.WET_GRASS)
.noCollission() .noCollission()
.offsetType(BlockBehaviour.OffsetType.XZ) .offsetType(BlockBehaviour.OffsetType.XZ))
); );
} }

View file

@ -150,7 +150,7 @@ public class BlocksHelper {
* @param random - {@link Random}. * @param random - {@link Random}.
* @return {@link Direction}. * @return {@link Direction}.
*/ */
public static Direction randomHorizontal(Random random) { public static Direction randomHorizontal(RandomSource random) {
return HORIZONTAL[random.nextInt(4)]; return HORIZONTAL[random.nextInt(4)];
} }
@ -160,7 +160,7 @@ public class BlocksHelper {
* @param random - {@link Random}. * @param random - {@link Random}.
* @return {@link Direction}. * @return {@link Direction}.
*/ */
public static Direction randomDirection(Random random) { public static Direction randomDirection(RandomSource random) {
return DIRECTIONS[random.nextInt(6)]; return DIRECTIONS[random.nextInt(6)];
} }

View file

@ -4,6 +4,7 @@ import com.mojang.math.Vector3f;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import java.util.Random;import net.minecraft.util.RandomSource; import java.util.Random;import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
public class MHelper { public class MHelper {
private static final Vec3i[] RANDOM_OFFSETS = new Vec3i[3 * 3 * 3 - 1]; 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 PHI = (float) (Math.PI * (3 - Math.sqrt(5)));
public static final float PI2 = (float) (Math.PI * 2); public static final float PI2 = (float) (Math.PI * 2);
public static final Random RANDOM = new Random(); 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); 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); 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); return min + random.nextFloat() * (max - min);
} }
@ -195,7 +197,7 @@ public class MHelper {
return (float) Math.acos(dot / Math.sqrt(length1 * length2)); 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 angleY = randRange(0, PI2, random);
float vx = (float) Math.sin(angleY); float vx = (float) Math.sin(angleY);
float vz = (float) Math.cos(angleY); float vz = (float) Math.cos(angleY);

View file

@ -55,7 +55,7 @@ public class SplineHelper {
return new Vector3f(x, y, z); return new Vector3f(x, y, z);
} }
public static void offsetParts(List<Vector3f> spline, Random random, float dx, float dy, float dz) { public static void offsetParts(List<Vector3f> spline, RandomSource random, float dx, float dy, float dz) {
int count = spline.size(); int count = spline.size();
for (int i = 1; i < count; i++) { for (int i = 1; i < count; i++) {
Vector3f pos = spline.get(i); Vector3f pos = spline.get(i);

View file

@ -130,6 +130,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
@Override @Override
public void setSeed(long seed) { public void setSeed(long seed) {
if (seed==currentSeed) return;
super.setSeed(seed); super.setSeed(seed);
biomePicker.rebuild(); biomePicker.rebuild();
initMap(seed); initMap(seed);

View file

@ -34,7 +34,7 @@ public class DoubleBlockSurfaceNoiseCondition extends SurfaceNoiseCondition {
final int z = context.getBlockZ(); final int z = context.getBlockZ();
if (lastX==x && lastZ==z) return lastValue > threshold; 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; lastX=x;
lastZ=z; lastZ=z;