salt RandomLocator and GaussianRandomLocator

This commit is contained in:
dfsek 2021-12-15 22:03:19 -07:00
parent 1fc139cc8c
commit 305c29dad2
4 changed files with 26 additions and 7 deletions

View File

@ -7,16 +7,17 @@
package com.dfsek.terra.addons.feature.locator.config; package com.dfsek.terra.addons.feature.locator.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value; import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate; import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
import com.dfsek.terra.addons.feature.locator.locators.GaussianRandomLocator; import com.dfsek.terra.addons.feature.locator.locators.GaussianRandomLocator;
import com.dfsek.terra.addons.feature.locator.locators.RandomLocator;
import com.dfsek.terra.api.config.meta.Meta; import com.dfsek.terra.api.config.meta.Meta;
import com.dfsek.terra.api.structure.feature.Locator; import com.dfsek.terra.api.structure.feature.Locator;
import com.dfsek.terra.api.util.Range; import com.dfsek.terra.api.util.Range;
@SuppressWarnings("FieldMayBeFinal")
public class GaussianRandomLocatorTemplate implements ObjectTemplate<Locator> { public class GaussianRandomLocatorTemplate implements ObjectTemplate<Locator> {
@Value("height") @Value("height")
private @Meta Range height; private @Meta Range height;
@ -27,8 +28,12 @@ public class GaussianRandomLocatorTemplate implements ObjectTemplate<Locator> {
@Value("standard-deviation") @Value("standard-deviation")
private double standardDeviation; private double standardDeviation;
@Value("salt")
@Default
private int salt = 0;
@Override @Override
public Locator get() { public Locator get() {
return new GaussianRandomLocator(height, amount, standardDeviation); return new GaussianRandomLocator(height, amount, standardDeviation, salt);
} }
} }

View File

@ -7,6 +7,7 @@
package com.dfsek.terra.addons.feature.locator.config; package com.dfsek.terra.addons.feature.locator.config;
import com.dfsek.tectonic.api.config.template.annotations.Default;
import com.dfsek.tectonic.api.config.template.annotations.Value; import com.dfsek.tectonic.api.config.template.annotations.Value;
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate; import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
@ -16,6 +17,7 @@ import com.dfsek.terra.api.structure.feature.Locator;
import com.dfsek.terra.api.util.Range; import com.dfsek.terra.api.util.Range;
@SuppressWarnings("FieldMayBeFinal")
public class RandomLocatorTemplate implements ObjectTemplate<Locator> { public class RandomLocatorTemplate implements ObjectTemplate<Locator> {
@Value("height") @Value("height")
private @Meta Range height; private @Meta Range height;
@ -23,8 +25,12 @@ public class RandomLocatorTemplate implements ObjectTemplate<Locator> {
@Value("amount") @Value("amount")
private @Meta Range amount; private @Meta Range amount;
@Value("salt")
@Default
private int salt = 0;
@Override @Override
public Locator get() { public Locator get() {
return new RandomLocator(height, amount); return new RandomLocator(height, amount, salt);
} }
} }

View File

@ -7,13 +7,13 @@
package com.dfsek.terra.addons.feature.locator.locators; package com.dfsek.terra.addons.feature.locator.locators;
import java.util.Random;
import com.dfsek.terra.api.structure.feature.BinaryColumn; import com.dfsek.terra.api.structure.feature.BinaryColumn;
import com.dfsek.terra.api.structure.feature.Locator; import com.dfsek.terra.api.structure.feature.Locator;
import com.dfsek.terra.api.util.Range; import com.dfsek.terra.api.util.Range;
import com.dfsek.terra.api.world.chunk.generation.util.Column; import com.dfsek.terra.api.world.chunk.generation.util.Column;
import java.util.Random;
public class GaussianRandomLocator implements Locator { public class GaussianRandomLocator implements Locator {
private final double mean; private final double mean;
@ -22,11 +22,14 @@ public class GaussianRandomLocator implements Locator {
private final double standardDeviation; private final double standardDeviation;
private final int salt;
public GaussianRandomLocator(Range height, Range points, double standardDeviation) {
public GaussianRandomLocator(Range height, Range points, double standardDeviation, int salt) {
this.mean = (height.getMax() + height.getMin()) / 2.0; this.mean = (height.getMax() + height.getMin()) / 2.0;
this.points = points; this.points = points;
this.standardDeviation = standardDeviation; this.standardDeviation = standardDeviation;
this.salt = salt;
} }
@Override @Override
@ -34,6 +37,7 @@ public class GaussianRandomLocator implements Locator {
long seed = column.getWorld().getSeed(); long seed = column.getWorld().getSeed();
seed = 31 * seed + column.getX(); seed = 31 * seed + column.getX();
seed = 31 * seed + column.getZ(); seed = 31 * seed + column.getZ();
seed += salt;
Random r = new Random(seed); Random r = new Random(seed);

View File

@ -20,9 +20,12 @@ public class RandomLocator implements Locator {
private final Range points; private final Range points;
public RandomLocator(Range height, Range points) { private final int salt;
public RandomLocator(Range height, Range points, int salt) {
this.height = height; this.height = height;
this.points = points; this.points = points;
this.salt = salt;
} }
@Override @Override
@ -30,6 +33,7 @@ public class RandomLocator implements Locator {
long seed = column.getWorld().getSeed(); long seed = column.getWorld().getSeed();
seed = 31 * seed + column.getX(); seed = 31 * seed + column.getX();
seed = 31 * seed + column.getZ(); seed = 31 * seed + column.getZ();
seed += salt;
Random r = new Random(seed); Random r = new Random(seed);