more cleanup

This commit is contained in:
dfsek 2021-02-20 23:59:17 -07:00
parent fab8c90e92
commit 03e9f6b882
10 changed files with 34 additions and 31 deletions

View File

@ -57,6 +57,8 @@ public class StructureScript {
throw new RuntimeException(e);
}
functionRegistry.forEach(parser::registerFunction); // Register registry functions.
parser.registerFunction("block", new BlockFunctionBuilder(main))
.registerFunction("check", new CheckFunctionBuilder(main, cache))
.registerFunction("structure", new StructureFunctionBuilder(registry, main))
@ -86,8 +88,6 @@ public class StructureScript {
.registerFunction("max", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.max(number.doubleValue(), number2.doubleValue())))
.registerFunction("min", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue())));
functionRegistry.forEach(parser::registerFunction); // Register registry functions.
block = parser.parse();
this.id = parser.getID();
tempID = id;

View File

@ -5,6 +5,7 @@ import com.dfsek.terra.api.platform.world.BiomeGrid;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.generator.ChunkData;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.world.generation.math.SamplerCache;
import org.jetbrains.annotations.NotNull;
import java.util.Random;
@ -27,4 +28,6 @@ public interface TerraChunkGenerator {
ConfigPack getConfigPack();
TerraPlugin getMain();
SamplerCache getCache();
}

View File

@ -1,4 +1,4 @@
package com.dfsek.terra.world.generation;
package com.dfsek.terra.world.generation.generators;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.api.math.Range;
@ -33,9 +33,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Random;
public class MasterChunkGenerator implements TerraChunkGenerator {
public class DefaultChunkGenerator3D implements TerraChunkGenerator {
private final ConfigPack configPack;
private final TerraPlugin main;
private final MaterialData water;
@ -46,7 +44,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
private final SamplerCache cache;
public MasterChunkGenerator(ConfigPack c, TerraPlugin main, SamplerCache cache) {
public DefaultChunkGenerator3D(ConfigPack c, TerraPlugin main, SamplerCache cache) {
this.configPack = c;
this.main = main;
carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main);
@ -102,8 +100,8 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
Sampler sampler = cache.getChunk(world, chunkX, chunkZ);
for(byte x = 0; x < 16; x++) {
for(byte z = 0; z < 16; z++) {
for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) {
int paletteLevel = 0;
int cx = xOrig + x;
@ -222,16 +220,17 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
int zOrig = (chunkZ << 4);
BiomeProvider grid = main.getWorld(world).getBiomeProvider();
for(int x = 0; x < 4; x++) {
for(byte z = 0; z < 4; z++) {
for(int z = 0; z < 4; z++) {
int cx = xOrig + (x << 2);
int cz = zOrig + (z << 2);
TerraBiome b = grid.getBiome(cx, cz);
biome.setBiome(x << 2, z << 2, b.getVanillaBiomes().get(b.getGenerator(world).getBiomeNoise(), cx, 0, cz));
biome.setBiome(cx, cz, b.getVanillaBiomes().get(b.getGenerator(world).getBiomeNoise(), cx, 0, cz));
}
}
}
@Override
public SamplerCache getCache() {
return cache;
}

View File

@ -53,8 +53,8 @@ public class BiomeChunkInterpolator implements ChunkInterpolator {
}
}
for(byte x = 0; x < 4; x++) {
for(byte z = 0; z < 4; z++) {
for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) {
for(int y = 0; y < 64; y++) {
interpGrid[x][y][z] = new Interpolator3(
noiseStorage[x][z][y],

View File

@ -20,8 +20,8 @@ public class NoiseChunkInterpolator implements ChunkInterpolator {
}
}
for(byte x = 0; x < 4; x++) {
for(byte z = 0; z < 4; z++) {
for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) {
for(int y = 0; y < 64; y++) {
interpGrid[x][y][z] = new Interpolator3(
noiseStorage[x][z][y],

View File

@ -14,6 +14,7 @@ import com.dfsek.terra.api.platform.handle.ItemHandle;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Biome;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.bukkit.command.command.TerraCommand;
import com.dfsek.terra.bukkit.command.command.structure.LocateCommand;
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
@ -34,7 +35,7 @@ import com.dfsek.terra.debug.DebugLogger;
import com.dfsek.terra.registry.master.AddonRegistry;
import com.dfsek.terra.registry.master.ConfigRegistry;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.generation.MasterChunkGenerator;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
import io.papermc.lib.PaperLib;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
@ -51,7 +52,7 @@ import java.util.Objects;
public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
private final Map<String, MasterChunkGenerator> generatorMap = new HashMap<>();
private final Map<String, DefaultChunkGenerator3D> generatorMap = new HashMap<>();
private final Map<World, TerraWorld> worldMap = new HashMap<>();
private final Map<String, ConfigPack> worlds = new HashMap<>();
private final ConfigRegistry registry = new ConfigRegistry();
@ -80,7 +81,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
public void reload() {
Map<World, TerraWorld> newMap = new HashMap<>();
worldMap.forEach((world, tw) -> {
((MasterChunkGenerator) ((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle()).getCache().clear();
((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle().getCache().clear();
String packID = tw.getConfig().getTemplate().getID();
newMap.put(world, new TerraWorld(world, registry.get(packID), this));
});
@ -205,7 +206,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
if(!registry.contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\"");
ConfigPack pack = registry.get(id);
worlds.put(worldName, pack);
return new MasterChunkGenerator(registry.get(id), this, pack.getSamplerCache());
return new DefaultChunkGenerator3D(registry.get(id), this, pack.getSamplerCache());
}));
}
@ -229,7 +230,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
throw new IllegalArgumentException("Not a Terra world! " + w.getGenerator());
if(!worlds.containsKey(w.getName())) {
getLogger().warning("Unexpected world load detected: \"" + w.getName() + "\"");
return new TerraWorld(w, ((MasterChunkGenerator) w.getGenerator().getHandle()).getConfigPack(), this);
return new TerraWorld(w, ((TerraChunkGenerator) w.getGenerator().getHandle()).getConfigPack(), this);
}
return worldMap.computeIfAbsent(w, world -> new TerraWorld(w, worlds.get(w.getName()), this));
}

View File

@ -200,7 +200,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
return debugLogger;
}
private Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
private final Transformer<String, Biome> biomeFixer = new Transformer.Builder<String, Biome>()
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>())
.addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build();

View File

@ -5,7 +5,7 @@ import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.world.TerraBiomeSource;
import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess;
import com.dfsek.terra.world.generation.MasterChunkGenerator;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
import com.dfsek.terra.world.population.FloraPopulator;
import com.dfsek.terra.world.population.OrePopulator;
import com.dfsek.terra.world.population.StructurePopulator;
@ -31,7 +31,7 @@ import net.minecraft.world.gen.chunk.VerticalBlockSample;
public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator {
private final long seed;
private final MasterChunkGenerator delegate;
private final DefaultChunkGenerator3D delegate;
private final TerraBiomeSource biomeSource;
public static final Codec<ConfigPack> PACK_CODEC = (RecordCodecBuilder.create(config -> config.group(
Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID())
@ -69,7 +69,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d
super(biomeSource, new StructuresConfig(false));
this.pack = configPack;
this.delegate = new MasterChunkGenerator(configPack, TerraFabricPlugin.getInstance(), pack.getSamplerCache());
this.delegate = new DefaultChunkGenerator3D(configPack, TerraFabricPlugin.getInstance(), pack.getSamplerCache());
delegate.getMain().getLogger().info("Loading world...");
this.biomeSource = biomeSource;
@ -77,7 +77,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d
}
@Override
public MasterChunkGenerator getHandle() {
public DefaultChunkGenerator3D getHandle() {
return delegate;
}

View File

@ -1,12 +1,12 @@
package com.dfsek.terra.platform;
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
import com.dfsek.terra.world.generation.MasterChunkGenerator;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
public class GenWrapper implements ChunkGenerator {
private final MasterChunkGenerator generator;
private final DefaultChunkGenerator3D generator;
public GenWrapper(MasterChunkGenerator generator) {
public GenWrapper(DefaultChunkGenerator3D generator) {
this.generator = generator;
}

View File

@ -4,7 +4,7 @@ import com.dfsek.terra.StandalonePlugin;
import com.dfsek.terra.platform.DirectChunkData;
import com.dfsek.terra.platform.DirectWorld;
import com.dfsek.terra.platform.GenWrapper;
import com.dfsek.terra.world.generation.MasterChunkGenerator;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
import com.dfsek.terra.world.generation.math.SamplerCache;
import com.dfsek.terra.world.population.FloraPopulator;
import com.dfsek.terra.world.population.OrePopulator;
@ -23,7 +23,7 @@ public class Generator {
StructurePopulator structurePopulator;
TreePopulator treePopulator;
OrePopulator orePopulator;
MasterChunkGenerator generator;
DefaultChunkGenerator3D generator;
public Generator(long seed, StandalonePlugin plugin) {
plugin.load();
@ -31,7 +31,7 @@ public class Generator {
structurePopulator = new StructurePopulator(plugin);
treePopulator = new TreePopulator(plugin);
orePopulator = new OrePopulator(plugin);
generator = new MasterChunkGenerator(plugin.getRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin));
generator = new DefaultChunkGenerator3D(plugin.getRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin));
this.seed = seed;
}