mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 14:50:56 +00:00
Random Changes
This commit is contained in:
+3
-3
@@ -28,7 +28,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
@@ -63,7 +63,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull ChunkData chunkData) {
|
||||
public void generateNoise(@NotNull WorldInfo worldInfo, @NotNull RandomGenerator random, int x, int z, @NotNull ChunkData chunkData) {
|
||||
BukkitWorldProperties properties = new BukkitWorldProperties(worldInfo);
|
||||
delegate.generateChunkData(new BukkitProtoChunk(chunkData), properties, pack.getBiomeProvider(), x, z);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class BukkitChunkGeneratorWrapper extends org.bukkit.generator.ChunkGener
|
||||
.stream()
|
||||
.map(generationStage -> new BlockPopulator() {
|
||||
@Override
|
||||
public void populate(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z,
|
||||
public void populate(@NotNull WorldInfo worldInfo, @NotNull RandomGenerator random, int x, int z,
|
||||
@NotNull LimitedRegion limitedRegion) {
|
||||
generationStage.populate(new BukkitProtoWorld(limitedRegion, air, pack.getBiomeProvider()));
|
||||
}
|
||||
|
||||
+5
-1
@@ -1,6 +1,8 @@
|
||||
package com.dfsek.terra.mod.mixin.gameplay;
|
||||
|
||||
|
||||
import com.dfsek.terra.mod.util.MinecraftAdapter;
|
||||
|
||||
import net.minecraft.item.BoneMealItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -14,6 +16,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.dfsek.terra.mod.util.FertilizableUtil;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
|
||||
@Mixin(BoneMealItem.class)
|
||||
public class BoneMealItemMixin {
|
||||
@@ -22,7 +26,7 @@ public class BoneMealItemMixin {
|
||||
@Inject(method = "useOnFertilizable", at = @At("HEAD"), cancellable = true)
|
||||
private static void injectUseOnFertilizable(ItemStack stack, World world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
|
||||
if(world instanceof ServerWorld) {
|
||||
Boolean value = FertilizableUtil.grow((ServerWorld) world, pos, world.getBlockState(pos), cooldownId);
|
||||
Boolean value = FertilizableUtil.grow((ServerWorld) world, MinecraftAdapter.adapt(world.getRandom()), pos, world.getBlockState(pos), cooldownId);
|
||||
stack.decrement(1);
|
||||
if(value != null) {
|
||||
cir.setReturnValue(value);
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.mod.mixin.gameplay;
|
||||
|
||||
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.mod.util.MinecraftAdapter;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -16,9 +16,9 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
@@ -42,7 +42,7 @@ public class BoneMealTaskMixin {
|
||||
if(villagerFertilizable) {
|
||||
Structure canGrow = config.getCanGrow();
|
||||
if(canGrow != null) {
|
||||
Random random = (Random) world.getRandom();
|
||||
RandomGenerator random = MinecraftAdapter.adapt(world.getRandom());
|
||||
cir.setReturnValue(canGrow.generate(
|
||||
Vector3Int.of(pos.getX(), pos.getY(), pos.getZ()), (WritableWorld) world, random, Rotation.NONE));
|
||||
return;
|
||||
|
||||
+5
-1
@@ -1,6 +1,8 @@
|
||||
package com.dfsek.terra.mod.mixin.gameplay;
|
||||
|
||||
|
||||
import com.dfsek.terra.mod.util.MinecraftAdapter;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -12,6 +14,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import com.dfsek.terra.mod.util.FertilizableUtil;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
public class ServerWorldMixin {
|
||||
@@ -22,7 +26,7 @@ public class ServerWorldMixin {
|
||||
target = "Lnet/minecraft/block/BlockState;randomTick(Lnet/minecraft/server/world/ServerWorld;" +
|
||||
"Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/random/Random;)V"))
|
||||
public void injectTickChunk(BlockState instance, ServerWorld serverWorld, BlockPos blockPos, Random random) {
|
||||
Boolean value = FertilizableUtil.grow(serverWorld, blockPos, instance, cooldownId);
|
||||
Boolean value = FertilizableUtil.grow(serverWorld, MinecraftAdapter.adapt(random), blockPos, instance, cooldownId);
|
||||
if(value != null) {
|
||||
if(!value) {
|
||||
instance.randomTick(serverWorld, blockPos, random);
|
||||
|
||||
+3
-12
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -10,9 +8,9 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
@@ -20,14 +18,7 @@ import com.dfsek.terra.mod.config.FertilizableConfig;
|
||||
|
||||
|
||||
public class FertilizableUtil {
|
||||
|
||||
private static final Random mojankRandom = new Random();
|
||||
|
||||
public static Boolean grow(ServerWorld world, BlockPos pos, BlockState state, Identifier cooldownId) {
|
||||
return grow(world, mojankRandom, pos, state, cooldownId);
|
||||
}
|
||||
|
||||
public static Boolean grow(ServerWorld world, Random random, BlockPos pos, BlockState state, Identifier cooldownId) {
|
||||
public static Boolean grow(ServerWorld world, RandomGenerator random, BlockPos pos, BlockState state, Identifier cooldownId) {
|
||||
Map<Identifier, FertilizableConfig> map = BiomeUtil.TERRA_BIOME_FERTILIZABLE_MAP.get(world.getBiome(pos));
|
||||
if(map != null) {
|
||||
Block block = state.getBlock();
|
||||
|
||||
@@ -18,11 +18,14 @@
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
import net.minecraft.world.HeightLimitView;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
|
||||
public final class MinecraftAdapter {
|
||||
|
||||
@@ -53,4 +56,48 @@ public final class MinecraftAdapter {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static RandomGenerator adapt(Random random) {
|
||||
return new RandomGenerator() {
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
return random.nextBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float nextFloat() {
|
||||
return random.nextFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble() {
|
||||
return random.nextDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt() {
|
||||
return random.nextInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(int bound) {
|
||||
return random.nextInt(bound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long nextLong() {
|
||||
return random.nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextGaussian() {
|
||||
return random.nextGaussian();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(int origin, int bound) {
|
||||
return random.nextBetween(origin, bound);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user