Skip to content

Commit

Permalink
Update Shapes API to use Mojang's Random.
Browse files Browse the repository at this point in the history
- New Shapes API methods using Mojang's Random are available
- Shapes API methods using java.util.Random are deprecated
  • Loading branch information
gniftygnome committed Dec 9, 2023
1 parent e33e5e7 commit b963974
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G
fabric.loom.multiProjectOptimisation=true

maven_group=com.terraformersmc.terraform-api
version=9.0.0-beta.1
version=9.0.0-beta.2

minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import com.terraformersmc.terraform.shapes.api.Filler;
import com.terraformersmc.terraform.shapes.api.Position;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.ModifiableWorld;

import java.util.Random;

public class RandomSimpleFiller implements Filler {

private final ModifiableWorld world;
Expand All @@ -23,19 +22,51 @@ public RandomSimpleFiller(ModifiableWorld world, BlockState state, int flags, Ra
this.probability = probability;
}

/**
* @deprecated Use the version accepting Mojang's {@link net.minecraft.util.math.random.Random} instead.
*/
@Deprecated
public RandomSimpleFiller(ModifiableWorld world, BlockState state, int flags, java.util.Random random, float probability) {
this(world, state, flags, Random.create(random.nextLong()), probability);
}

public RandomSimpleFiller(ModifiableWorld world, BlockState state, Random random, float probability) {
this(world, state, 3, random, probability);
}

public static RandomSimpleFiller of(ModifiableWorld world, BlockState state, int flags, Random random, float proability) {
return new RandomSimpleFiller(world, state, flags, random, proability);
/**
* @deprecated Use the version accepting Mojang's {@link net.minecraft.util.math.random.Random} instead.
*/
@Deprecated
public RandomSimpleFiller(ModifiableWorld world, BlockState state, java.util.Random random, float probability) {
this(world, state, 3, random, probability);
}

public static RandomSimpleFiller of(ModifiableWorld world, BlockState state, int flags, Random random, float probability) {
return new RandomSimpleFiller(world, state, flags, random, probability);
}

public static RandomSimpleFiller of(ModifiableWorld world, BlockState state, Random random, float proability) {
return new RandomSimpleFiller(world, state, random, proability);
/**
* @deprecated Use the version accepting Mojang's {@link net.minecraft.util.math.random.Random} instead.
*/
@Deprecated
public static RandomSimpleFiller of(ModifiableWorld world, BlockState state, int flags, java.util.Random random, float probability) {
return new RandomSimpleFiller(world, state, flags, random, probability);
}

public static RandomSimpleFiller of(ModifiableWorld world, BlockState state, Random random, float probability) {
return new RandomSimpleFiller(world, state, random, probability);
}

@Override
/**
* @deprecated Use the version accepting Mojang's {@link net.minecraft.util.math.random.Random} instead.
*/
@Deprecated
public static RandomSimpleFiller of(ModifiableWorld world, BlockState state, java.util.Random random, float probability) {
return new RandomSimpleFiller(world, state, random, probability);
}

@Override
public void accept(Position position) {
if (this.random.nextFloat() < this.probability) {
world.setBlockState(position.toBlockPos(), this.state, this.flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.terraformersmc.terraform.shapes.api.Position;
import com.terraformersmc.terraform.shapes.api.Shape;
import com.terraformersmc.terraform.shapes.api.layer.Layer;
import net.minecraft.util.math.random.Random;

import java.util.Random;
import java.util.function.Predicate;

public class NoiseTranslateLayer implements Layer {
Expand All @@ -17,9 +17,24 @@ public NoiseTranslateLayer(double magnitude, Random random) {
this.random = random;
}

public static NoiseTranslateLayer of(double magnitude, Random random) {
return new NoiseTranslateLayer(magnitude, random);
}
/**
* @deprecated Use the version accepting Mojang's {@link net.minecraft.util.math.random.Random} instead.
*/
@Deprecated
public NoiseTranslateLayer(double magnitude, java.util.Random random) {
this(magnitude, Random.create(random.nextLong()));
}

public static NoiseTranslateLayer of(double magnitude, Random random) {
return new NoiseTranslateLayer(magnitude, random);
}

/**
* @deprecated Use the version accepting Mojang's {@link net.minecraft.util.math.random.Random} instead.
*/
public static NoiseTranslateLayer of(double magnitude, java.util.Random random) {
return new NoiseTranslateLayer(magnitude, random);
}


@Override
Expand Down

0 comments on commit b963974

Please sign in to comment.