mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
clean up chunkgenerator stuff
This commit is contained in:
+8
-3
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.NoiseChunkGeneratorPackConfigTemplate;
|
||||
import com.dfsek.terra.addons.chunkgenerator.generation.generators.NoiseChunkGenerator3D;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolder;
|
||||
import com.dfsek.terra.addons.chunkgenerator.palette.PaletteHolderLoader;
|
||||
@@ -36,12 +37,16 @@ public class NoiseChunkGenerator3DAddon implements AddonInitializer {
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().getOrCreateRegistry(ChunkGeneratorProvider.class).register("NOISE_3D",
|
||||
pack -> new NoiseChunkGenerator3D(pack,
|
||||
platform));
|
||||
NoiseChunkGeneratorPackConfigTemplate config = event.loadTemplate(new NoiseChunkGeneratorPackConfigTemplate());
|
||||
|
||||
event.getPack()
|
||||
.getOrCreateRegistry(ChunkGeneratorProvider.class)
|
||||
.register("NOISE_3D",
|
||||
pack -> new NoiseChunkGenerator3D(pack, platform, config.getElevationBlend()));
|
||||
event.getPack()
|
||||
.applyLoader(SlantHolder.class, new SlantHolderLoader())
|
||||
.applyLoader(PaletteHolder.class, new PaletteHolderLoader());
|
||||
|
||||
})
|
||||
.failThrough();
|
||||
|
||||
|
||||
+9
-2
@@ -11,6 +11,8 @@ import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -39,12 +41,17 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
private final Platform platform;
|
||||
private final List<GenerationStage> generationStages = new ArrayList<>();
|
||||
|
||||
private final int elevationBlend;
|
||||
|
||||
private final SamplerProvider samplerCache;
|
||||
|
||||
private final BlockState air;
|
||||
|
||||
public NoiseChunkGenerator3D(ConfigPack c, Platform platform) {
|
||||
public NoiseChunkGenerator3D(ConfigPack c, Platform platform, int elevationBlend) {
|
||||
this.configPack = c;
|
||||
this.platform = platform;
|
||||
this.air = platform.getWorldHandle().air();
|
||||
this.elevationBlend = elevationBlend;
|
||||
c.getStages().forEach(stage -> generationStages.add(stage.newInstance(c)));
|
||||
}
|
||||
|
||||
@@ -59,7 +66,7 @@ public class NoiseChunkGenerator3D implements ChunkGenerator {
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
|
||||
Sampler sampler = world.getConfig().getSamplerCache().getChunk(chunkX, chunkZ);
|
||||
Sampler sampler = samplerCache.getChunk(chunkX, chunkZ);
|
||||
|
||||
long seed = world.getSeed();
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.world;
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.samplers;
|
||||
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
+1
-2
@@ -109,8 +109,7 @@ public class NoiseAddon implements AddonInitializer {
|
||||
noiseRegistry.register("EXPRESSION", () -> new ExpressionFunctionTemplate(packSamplers, packFunctions));
|
||||
|
||||
|
||||
NoiseConfigPackTemplate template = new NoiseConfigPackTemplate();
|
||||
event.loadTemplate(template);
|
||||
NoiseConfigPackTemplate template = event.loadTemplate(new NoiseConfigPackTemplate());
|
||||
packSamplers.putAll(template.getSamplers());
|
||||
packFunctions.putAll(template.getFunctions());
|
||||
})
|
||||
|
||||
@@ -13,18 +13,13 @@ import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.util.StringIdentifiable;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
|
||||
|
||||
public interface WorldConfig extends StringIdentifiable {
|
||||
int elevationBlend();
|
||||
|
||||
<T> Registry<T> getRegistry(Class<T> clazz);
|
||||
|
||||
ServerWorld getWorld();
|
||||
|
||||
SamplerProvider getSamplerCache();
|
||||
|
||||
BiomeProvider getProvider();
|
||||
|
||||
ConfigPack getPack();
|
||||
|
||||
+2
-1
@@ -32,8 +32,9 @@ public abstract class ConfigPackLoadEvent implements PackEvent, FailThroughEvent
|
||||
*
|
||||
* @param template Template to register.
|
||||
*/
|
||||
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||
public <T extends ConfigTemplate> T loadTemplate(T template) throws ConfigException {
|
||||
configLoader.accept(template);
|
||||
return template;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.api.world;
|
||||
|
||||
import com.dfsek.terra.api.Handle;
|
||||
import com.dfsek.terra.api.config.WorldConfig;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
|
||||
@@ -16,6 +15,4 @@ public interface World extends Handle {
|
||||
ChunkGenerator getGenerator();
|
||||
|
||||
BiomeProvider getBiomeProvider();
|
||||
|
||||
WorldConfig getConfig();
|
||||
}
|
||||
|
||||
-3
@@ -166,7 +166,6 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
logger.error("Failed to load config pack from folder \"{}\"", folder.getAbsolutePath(), e);
|
||||
throw e;
|
||||
}
|
||||
toWorldConfig(new DummyServerWorld()); // Build now to catch any errors immediately.
|
||||
}
|
||||
|
||||
public ConfigPackImpl(ZipFile file, Platform platform) throws ConfigException {
|
||||
@@ -219,8 +218,6 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
logger.error("Failed to load config pack from ZIP archive \"{}\"", file.getName());
|
||||
throw e;
|
||||
}
|
||||
|
||||
toWorldConfig(new DummyServerWorld()); // Build now to catch any errors immediately.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-14
@@ -27,14 +27,11 @@ import com.dfsek.terra.api.config.WorldConfig;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.math.SamplerProvider;
|
||||
import com.dfsek.terra.registry.LockedRegistryImpl;
|
||||
import com.dfsek.terra.world.SamplerProviderImpl;
|
||||
|
||||
|
||||
public class WorldConfigImpl implements WorldConfig {
|
||||
private final SamplerProvider samplerProvider;
|
||||
|
||||
private final BiomeProvider provider;
|
||||
|
||||
private final ServerWorld world;
|
||||
@@ -45,18 +42,12 @@ public class WorldConfigImpl implements WorldConfig {
|
||||
public WorldConfigImpl(ServerWorld world, ConfigPackImpl pack, Platform platform) {
|
||||
this.world = world;
|
||||
this.pack = pack;
|
||||
this.samplerProvider = new SamplerProviderImpl(platform, world);
|
||||
|
||||
pack.getRegistryMap().forEach((clazz, pair) -> registryMap.put(clazz, new LockedRegistryImpl<>(pair.getLeft())));
|
||||
|
||||
this.provider = pack.getBiomeProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int elevationBlend() {
|
||||
return pack.getTemplate().getElevationBlend();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Registry<T> getRegistry(Class<T> clazz) {
|
||||
@@ -68,11 +59,6 @@ public class WorldConfigImpl implements WorldConfig {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SamplerProvider getSamplerCache() {
|
||||
return samplerProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getProvider() {
|
||||
return provider;
|
||||
|
||||
Reference in New Issue
Block a user