updated decorator data to use rand instead of seed

This commit is contained in:
Unknown
2019-12-15 09:54:03 -05:00
parent 235fff9426
commit f9f3c88cfd
4 changed files with 5 additions and 57 deletions
@@ -2,19 +2,9 @@ package kaptainwutax.seedcracker.cracker.population;
import kaptainwutax.seedcracker.cracker.DecoratorCache;
import kaptainwutax.seedcracker.util.Rand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.ChunkRandom;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.decorator.ConfiguredDecorator;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class DecoratorData {
@@ -39,7 +29,7 @@ public abstract class DecoratorData {
decoratorSeed += salt;
decoratorSeed ^= Rand.JAVA_LCG.multiplier;
decoratorSeed &= Rand.JAVA_LCG.modulo - 1;
return this.testDecorator(decoratorSeed);
return this.testDecorator(new Rand(decoratorSeed, false));
}
public long getPopulationSeed(long structureSeed, int x, int z) {
@@ -49,7 +39,7 @@ public abstract class DecoratorData {
return (long)x * a + (long)z * b ^ structureSeed;
}
public abstract boolean testDecorator(long decoratorSeed);
public abstract boolean testDecorator(Rand rand);
@Override
public boolean equals(Object obj) {
@@ -63,42 +53,4 @@ public abstract class DecoratorData {
return false;
}
public abstract static class Feature {
private Map<Biome, Long> CACHE = new HashMap<>();
private GenerationStep.Feature genStep;
private Decorator decorator;
public Feature(GenerationStep.Feature genStep, Decorator decorator) {
this.genStep = genStep;
this.decorator = decorator;
}
public ChunkRandom buildRand(long worldSeed, Biome biome, ChunkPos chunkPos) {
if(CACHE.containsKey(biome)) {
return new ChunkRandom(CACHE.get(biome));
}
List<ConfiguredFeature<?, ?>> features = biome.getFeaturesForStep(this.genStep);
for(int i = 0; i < features.size(); i++) {
ConfiguredFeature<?, ?> feature = features.get(i);
if(!(feature.config instanceof DecoratedFeatureConfig))continue;
ConfiguredDecorator<?> currentDecorator = ((DecoratedFeatureConfig)feature.config).decorator;
if(currentDecorator.decorator == this.decorator) {
BlockPos pos = new BlockPos(chunkPos.getStartX(), 0, chunkPos.getStartZ());
ChunkRandom chunkRandom = new ChunkRandom();
long populationSeed = chunkRandom.setSeed(worldSeed, pos.getX(), pos.getZ());
long seed = chunkRandom.setFeatureSeed(populationSeed, i, this.genStep.ordinal());
CACHE.put(biome, seed ^ Rand.JAVA_LCG.multiplier);
return chunkRandom;
}
}
return null;
}
}
}
@@ -28,9 +28,8 @@ public class DungeonData extends DecoratorData {
}
@Override
public boolean testDecorator(long decoratorSeed) {
public boolean testDecorator(Rand rand) {
if(this.starts.isEmpty())return true;
Rand rand = new Rand(decoratorSeed, false);
//TODO: This currently only supports 1 dungeon per chunk.
BlockPos start = this.starts.get(0);
@@ -30,13 +30,12 @@ public class EmeraldOreData extends DecoratorData {
}
@Override
public boolean testDecorator(long decoratorSeed) {
public boolean testDecorator(Rand rand) {
if(this.starts.isEmpty())return true;
//TODO: This currently only supports 1 emerald per chunk.
BlockPos start = this.starts.get(0);
Rand rand = new Rand(decoratorSeed, false);
int b = rand.nextInt(6);
for(int i = 0; i < b + 3; i++) {
@@ -20,9 +20,7 @@ public class EndGatewayData extends DecoratorData {
}
@Override
public boolean testDecorator(long decoratorSeed) {
Rand rand = new Rand(decoratorSeed, false);
public boolean testDecorator(Rand rand) {
if(rand.nextInt(700) != 0)return false;
if(rand.nextInt(16) != this.xOffset)return false;
if(rand.nextInt(16) != this.zOffset)return false;