- steppier steppes & plainier plains

- more tree types converted to poisson/context decorators
- more work on threadpool/batching
This commit is contained in:
dags- 2020-05-15 22:21:13 +01:00
parent 3a342bba96
commit b935b9ab81
68 changed files with 403 additions and 248 deletions

2
Engine

@ -1 +1 @@
Subproject commit 67af3049fe2b82e8edb5cf0afb87cdf8314b2c97
Subproject commit 72118adaa8891b76dda2405c76f0d985f81cd614

View File

@ -28,10 +28,10 @@ package com.terraforged;
import com.terraforged.api.material.WGTags;
import com.terraforged.command.TerraCommand;
import com.terraforged.data.DataGen;
import com.terraforged.feature.context.ContextSelectorFeature;
import com.terraforged.feature.decorator.poisson.PoissonAtSurface;
import com.terraforged.feature.feature.DiskFeature;
import com.terraforged.fm.template.TemplateManager;
import com.terraforged.feature.context.ContextSelectorFeature;
import com.terraforged.settings.SettingsHelper;
import com.terraforged.util.DataPackFinder;
import com.terraforged.util.Environment;

View File

@ -25,8 +25,8 @@
package com.terraforged.api.biome.modifier;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.Seed;
import com.terraforged.core.cell.Cell;
import com.terraforged.world.climate.Climate;
import me.dags.noise.Module;
import me.dags.noise.Source;

View File

@ -30,10 +30,10 @@ import com.terraforged.api.chunk.column.DecoratorManager;
import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.api.material.geology.GeologyManager;
import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.fm.modifier.FeatureModifiers;
import com.terraforged.fm.structure.StructureManager;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.terrain.provider.TerrainProvider;
import com.terraforged.fm.modifier.FeatureModifiers;
import net.minecraftforge.eventbus.api.Event;
public abstract class SetupEvent<T> extends Event {

View File

@ -28,9 +28,9 @@ package com.terraforged.biome.map;
import com.google.common.collect.Sets;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.terraforged.biome.ModBiomes;
import com.terraforged.biome.provider.BiomeHelper;
import com.terraforged.world.biome.BiomeType;
import com.terraforged.biome.ModBiomes;
import me.dags.noise.util.NoiseUtil;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;

View File

@ -27,9 +27,9 @@ package com.terraforged.biome.map;
import com.terraforged.biome.provider.BiomeHelper;
import com.terraforged.core.util.grid.FixedGrid;
import com.terraforged.util.ListUtils;
import com.terraforged.world.biome.BiomeData;
import com.terraforged.world.biome.BiomeType;
import com.terraforged.util.ListUtils;
import net.minecraft.world.biome.Biome;
import java.util.ArrayList;

View File

@ -25,8 +25,8 @@
package com.terraforged.biome.modifier;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.Seed;
import com.terraforged.core.cell.Cell;
import com.terraforged.world.climate.Climate;
import me.dags.noise.Module;
import me.dags.noise.Source;

View File

@ -27,11 +27,11 @@ package com.terraforged.biome.modifier;
import com.terraforged.api.biome.modifier.BiomeModifier;
import com.terraforged.api.biome.modifier.ModifierManager;
import com.terraforged.biome.map.BiomeMap;
import com.terraforged.biome.provider.DesertBiomes;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.cell.Cell;
import com.terraforged.world.biome.BiomeType;
import com.terraforged.biome.map.BiomeMap;
import com.terraforged.chunk.TerraContext;
import net.minecraft.world.biome.Biome;
import java.util.ArrayList;

View File

@ -0,0 +1,24 @@
package com.terraforged.biome.modifier;
import com.terraforged.api.biome.modifier.BiomeModifier;
import com.terraforged.core.cell.Cell;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
public class DunesModifier implements BiomeModifier {
@Override
public int priority() {
return 0;
}
@Override
public boolean test(Biome biome) {
return biome.getCategory() == Biome.Category.DESERT;
}
@Override
public Biome modify(Biome in, Cell cell, int x, int z) {
return Biomes.DESERT;
}
}

View File

@ -25,8 +25,8 @@
package com.terraforged.biome.modifier;
import com.terraforged.core.cell.Cell;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.cell.Cell;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraftforge.registries.ForgeRegistries;
@ -53,7 +53,7 @@ public class SandBiomeModifier extends AbstractMaxHeightModifier {
@Override
public boolean test(Biome biome) {
return biome.getCategory() == Biome.Category.DESERT || biomes.contains(biome);
return biome.getCategory() == Biome.Category.DESERT && biomes.contains(biome);
}
@Override

View File

@ -25,12 +25,12 @@
package com.terraforged.biome.provider;
import com.terraforged.world.biome.BiomeData;
import com.terraforged.world.biome.BiomeType;
import com.terraforged.biome.ModBiomes;
import com.terraforged.biome.map.BiomeMap;
import com.terraforged.biome.map.BiomeMapBuilder;
import com.terraforged.biome.map.BiomePredicate;
import com.terraforged.world.biome.BiomeData;
import com.terraforged.world.biome.BiomeType;
import me.dags.noise.util.Vec2f;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;

View File

@ -26,15 +26,15 @@
package com.terraforged.biome.provider;
import com.google.common.collect.Sets;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.world.terrain.decorator.Decorator;
import com.terraforged.world.heightmap.WorldLookup;
import com.terraforged.biome.map.BiomeMap;
import com.terraforged.biome.modifier.BiomeModifierManager;
import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.chunk.TerraContext;
import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.util.setup.SetupHooks;
import com.terraforged.world.heightmap.WorldLookup;
import com.terraforged.world.terrain.decorator.Decorator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;

View File

@ -27,7 +27,7 @@ package com.terraforged.biome.provider;
import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.api.material.layer.LayerMaterial;
import com.terraforged.core.concurrent.ObjectPool;
import com.terraforged.core.concurrent.Resource;
import com.terraforged.material.Materials;
import com.terraforged.util.DummyBlockReader;
import com.terraforged.util.ListUtils;
@ -60,10 +60,10 @@ public class DesertBiomes {
public DesertBiomes(Materials materials, List<Biome> deserts) {
List<Biome> white = new LinkedList<>();
List<Biome> red = new LinkedList<>();
try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) {
try (Resource<DummyBlockReader> reader = DummyBlockReader.pooled()) {
for (Biome biome : deserts) {
BlockState top = biome.getSurfaceBuilderConfig().getTop();
MaterialColor color = top.getMaterialColor(reader.getValue().set(top), BlockPos.ZERO);
MaterialColor color = top.getMaterialColor(reader.get().set(top), BlockPos.ZERO);
int whiteDist2 = distance2(color, MaterialColor.SAND);
int redDist2 = distance2(color, MaterialColor.ADOBE);
if (whiteDist2 < redDist2) {

View File

@ -1,8 +1,8 @@
package com.terraforged.biome.spawn;
import com.terraforged.Log;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.world.continent.MutableVeci;
import com.terraforged.Log;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.Feature;

View File

@ -1,9 +1,9 @@
package com.terraforged.biome.spawn;
import com.terraforged.Log;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.command.search.Search;
import com.terraforged.core.cell.Cell;
import com.terraforged.Log;
import net.minecraft.util.math.BlockPos;
public class SpawnSearch extends Search {

View File

@ -25,8 +25,8 @@
package com.terraforged.biome.tag;
import com.terraforged.api.biome.BiomeTags;
import com.terraforged.Log;
import com.terraforged.api.biome.BiomeTags;
import net.minecraft.profiler.IProfiler;
import net.minecraft.resources.IFutureReloadListener;
import net.minecraft.resources.IResourceManager;

View File

@ -25,26 +25,26 @@
package com.terraforged.chunk;
import com.terraforged.Log;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.region.Size;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.core.region.gen.RegionCache;
import com.terraforged.fm.structure.StructureManager;
import com.terraforged.fm.FeatureManager;
import com.terraforged.material.Materials;
import com.terraforged.material.geology.GeoManager;
import com.terraforged.fm.data.DataManager;
import com.terraforged.Log;
import com.terraforged.chunk.generator.BiomeGenerator;
import com.terraforged.chunk.generator.MobGenerator;
import com.terraforged.chunk.generator.StructureGenerator;
import com.terraforged.chunk.generator.TerrainCarver;
import com.terraforged.chunk.generator.TerrainGenerator;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.region.Size;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.core.region.gen.RegionCache;
import com.terraforged.feature.BlockDataManager;
import com.terraforged.fm.FeatureManager;
import com.terraforged.fm.data.DataManager;
import com.terraforged.fm.structure.StructureManager;
import com.terraforged.material.Materials;
import com.terraforged.material.geology.GeoManager;
import com.terraforged.util.Environment;
import com.terraforged.util.setup.SetupHooks;
import net.minecraft.entity.EntityClassification;

View File

@ -28,15 +28,15 @@ package com.terraforged.chunk;
import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.core.concurrent.pool.ThreadPools;
import com.terraforged.core.region.gen.RegionCache;
import com.terraforged.core.region.gen.RegionGenerator;
import com.terraforged.core.concurrent.ThreadPool;
import com.terraforged.material.Materials;
import com.terraforged.settings.TerraSettings;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.WorldGeneratorFactory;
import com.terraforged.world.heightmap.Heightmap;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.settings.TerraSettings;
import net.minecraft.world.IWorld;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.GenerationSettings;
@ -76,7 +76,7 @@ public class TerraContext extends GeneratorContext {
return RegionGenerator.builder()
.factory(factory)
.size(3, 2)
.pool(ThreadPool.getPool())
.pool(ThreadPools.getPool())
.batch(6)
.build()
.toCache();

View File

@ -1,30 +1,29 @@
package com.terraforged.chunk;
import com.terraforged.Log;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.biome.ModBiomes;
import com.terraforged.biome.surface.IcebergsSurface;
import com.terraforged.biome.surface.SwampSurface;
import com.terraforged.decorator.feature.LayerDecorator;
import com.terraforged.decorator.feature.SnowEroder;
import com.terraforged.chunk.column.BedrockDecorator;
import com.terraforged.chunk.column.CoastDecorator;
import com.terraforged.chunk.column.ErosionDecorator;
import com.terraforged.chunk.column.GeologyDecorator;
import com.terraforged.chunk.column.post.LayerDecorator;
import com.terraforged.chunk.column.post.SnowEroder;
import com.terraforged.feature.BlockDataManager;
import com.terraforged.feature.Matchers;
import com.terraforged.fm.structure.StructureManager;
import com.terraforged.fm.FeatureManager;
import com.terraforged.fm.data.DataManager;
import com.terraforged.fm.matcher.biome.BiomeMatcher;
import com.terraforged.fm.matcher.feature.FeatureMatcher;
import com.terraforged.fm.modifier.FeatureModifiers;
import com.terraforged.fm.predicate.DeepWater;
import com.terraforged.fm.predicate.FeaturePredicate;
import com.terraforged.fm.predicate.MinDepth;
import com.terraforged.fm.predicate.MinHeight;
import com.terraforged.fm.structure.StructureManager;
import com.terraforged.material.geology.GeoManager;
import com.terraforged.Log;
import com.terraforged.decorator.terrain.BedrockDecorator;
import com.terraforged.decorator.terrain.CoastDecorator;
import com.terraforged.decorator.terrain.ErosionDecorator;
import com.terraforged.decorator.terrain.GeologyDecorator;
import com.terraforged.feature.BlockDataManager;
import com.terraforged.fm.data.DataManager;
import com.terraforged.util.setup.SetupHooks;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.decorator.terrain;
package com.terraforged.chunk.column;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.decorator;
package com.terraforged.chunk.column;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.decorator.terrain;
package com.terraforged.chunk.column;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.decorator.terrain;
package com.terraforged.chunk.column;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.decorator.terrain;
package com.terraforged.chunk.column;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
package com.terraforged.decorator.feature;
package com.terraforged.chunk.column.post;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;

View File

@ -23,12 +23,12 @@
* SOFTWARE.
*/
package com.terraforged.decorator.feature;
package com.terraforged.chunk.column.post;
import com.terraforged.api.chunk.column.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.chunk.TerraContext;
import com.terraforged.decorator.terrain.ErosionDecorator;
import com.terraforged.chunk.column.ErosionDecorator;
import me.dags.noise.source.Rand;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;

View File

@ -5,12 +5,12 @@ import com.terraforged.api.chunk.column.DecoratorContext;
import com.terraforged.api.chunk.surface.ChunkSurfaceBuffer;
import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.column.ChunkPopulator;
import com.terraforged.chunk.fix.RegionFix;
import com.terraforged.chunk.util.FastChunk;
import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.feature.TerrainHelper;
import com.terraforged.decorator.ChunkPopulator;
import com.terraforged.util.Environment;
import net.minecraft.util.SharedSeedRandom;
import net.minecraft.util.math.BlockPos;

View File

@ -25,10 +25,10 @@
package com.terraforged.chunk.test;
import com.terraforged.biome.ModBiomes;
import com.terraforged.world.terrain.Terrain;
import com.terraforged.world.terrain.Terrains;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
public class Test {
@ -39,6 +39,6 @@ public class Test {
}
public static Biome getBiome() {
return ModBiomes.STEPPE;
return Biomes.PLAINS;
}
}

View File

@ -25,13 +25,13 @@
package com.terraforged.chunk.test;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.cell.Populator;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.heightmap.WorldHeightmap;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.TerraContext;
import net.minecraft.world.gen.GenerationSettings;
public class TestChunkGenerator extends TerraChunkGenerator {

View File

@ -31,7 +31,10 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.terraforged.Log;
import com.terraforged.biome.provider.BiomeProvider;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.TerraContext;
import com.terraforged.command.arg.BiomeArgType;
import com.terraforged.command.arg.TerrainArgType;
import com.terraforged.command.search.BiomeSearchTask;
@ -39,14 +42,11 @@ import com.terraforged.command.search.BothSearchTask;
import com.terraforged.command.search.Search;
import com.terraforged.command.search.TerrainSearchTask;
import com.terraforged.core.cell.Cell;
import com.terraforged.data.DataGen;
import com.terraforged.settings.SettingsHelper;
import com.terraforged.world.WorldGenerator;
import com.terraforged.world.terrain.Terrain;
import com.terraforged.world.terrain.Terrains;
import com.terraforged.Log;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.TerraContext;
import com.terraforged.data.DataGen;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.ArgumentSerializer;

View File

@ -3,8 +3,9 @@ package com.terraforged.feature.context;
import com.terraforged.chunk.fix.RegionDelegate;
import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.core.concurrent.ObjectPool;
import com.terraforged.core.concurrent.Resource;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.world.heightmap.Levels;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
@ -46,8 +47,11 @@ public class ChanceContext {
}
int nextIndex(Random random) {
if (total == 0) {
return -1;
}
float value = 0F;
float chance = random.nextFloat() * total;
float chance = total * random.nextFloat();
for (int i = 0; i < length; i++) {
value += buffer[i];
if (value >= chance) {
@ -57,7 +61,7 @@ public class ChanceContext {
return -1;
}
public static ObjectPool.Item<ChanceContext> pooled(IWorld world) {
public static Resource<ChanceContext> pooled(IWorld world) {
if (world instanceof RegionDelegate) {
Levels levels = new Levels(world.getMaxHeight(), world.getSeaLevel());
WorldGenRegion region = ((RegionDelegate) world).getRegion();
@ -67,12 +71,12 @@ public class ChanceContext {
return null;
}
public static ObjectPool.Item<ChanceContext> pooled(IChunk chunk, Levels levels) {
public static Resource<ChanceContext> pooled(IChunk chunk, Levels levels) {
BiomeContainer container = chunk.getBiomes();
if (container instanceof TerraContainer) {
ChunkReader reader = ((TerraContainer) container).getChunkReader();
ObjectPool.Item<ChanceContext> item = pool.get();
ChanceContext context = item.getValue();
Resource<ChanceContext> item = pool.get();
ChanceContext context = item.get();
context.chunk = chunk;
context.levels = levels;
context.reader = reader;

View File

@ -1,6 +1,6 @@
package com.terraforged.feature.context;
import com.terraforged.core.concurrent.ObjectPool;
import com.terraforged.core.concurrent.Resource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.ChunkGenerator;
@ -20,12 +20,12 @@ public class ContextSelectorFeature extends Feature<ContextSelectorConfig> {
@Override
public boolean place(IWorld world, ChunkGenerator<? extends GenerationSettings> generator, Random random, BlockPos pos, ContextSelectorConfig config) {
try (ObjectPool.Item<ChanceContext> item = ChanceContext.pooled(world)) {
try (Resource<ChanceContext> item = ChanceContext.pooled(world)) {
if (item == null) {
return false;
}
ChanceContext context = item.getValue();
ChanceContext context = item.get();
context.setPos(pos);
context.init(config.features.size());
for (int i = 0; i < config.features.size(); i++) {

View File

@ -6,8 +6,8 @@ import net.minecraft.util.math.BlockPos;
public class Biome extends RangeContextModifier {
public Biome(float chance, float min, float max) {
super(min, max);
public Biome(float from, float to, boolean exclusive) {
super(from, to, exclusive);
}
@Override
@ -21,9 +21,6 @@ public class Biome extends RangeContextModifier {
}
public static ContextModifier deserialize(Dynamic<?> dynamic) {
float chance = dynamic.get("chance").asFloat(0F);
float min = dynamic.get("min").asFloat(0F);
float max = dynamic.get("max").asFloat(1F);
return new Biome(chance, min, max);
return RangeContextModifier.deserialize(dynamic, Biome::new);
}
}

View File

@ -6,8 +6,8 @@ import net.minecraft.util.math.BlockPos;
public class Elevation extends RangeContextModifier {
public Elevation(float min, float max) {
super(min, max);
public Elevation(float from, float to, boolean exclusive) {
super(from, to, exclusive);
}
@Override
@ -21,8 +21,6 @@ public class Elevation extends RangeContextModifier {
}
public static ContextModifier deserialize(Dynamic<?> dynamic) {
float min = dynamic.get("min").asFloat(0F);
float max = dynamic.get("max").asFloat(1F);
return new Elevation(min, max);
return RangeContextModifier.deserialize(dynamic, Elevation::new);
}
}

View File

@ -9,10 +9,12 @@ import net.minecraft.util.math.BlockPos;
public abstract class RangeContextModifier extends RangeModifier implements ContextModifier {
public RangeContextModifier(float min, float max) {
super(min, max);
public RangeContextModifier(float min, float max, boolean exclusive) {
super(min, max, exclusive);
}
protected abstract float getValue(BlockPos pos, ChanceContext context);
@Override
public float getChance(BlockPos pos, ChanceContext context) {
return apply(getValue(pos, context));
@ -21,10 +23,21 @@ public abstract class RangeContextModifier extends RangeModifier implements Cont
@Override
public <T> Dynamic<T> serialize(DynamicOps<T> ops) {
return new Dynamic<>(ops, ops.createMap(ImmutableMap.of(
ops.createString("min"), ops.createFloat(min),
ops.createString("max"), ops.createFloat(max)
ops.createString("from"), ops.createFloat(from),
ops.createString("to"), ops.createFloat(to),
ops.createString("exclusive"), ops.createBoolean(max > 0)
)));
}
protected abstract float getValue(BlockPos pos, ChanceContext context);
public static <T extends RangeContextModifier> T deserialize(Dynamic<?> dynamic, Factory<T> factory) {
float from = dynamic.get("from").asFloat(0F);
float to = dynamic.get("to").asFloat(1F);
boolean exclusive = dynamic.get("exclusive").asBoolean(false);
return factory.create(from, to, exclusive);
}
public interface Factory<T extends RangeContextModifier> {
T create(float from, float to, boolean exclusive);
}
}

View File

@ -1,9 +1,9 @@
package com.terraforged.feature.decorator.poisson;
import com.terraforged.chunk.fix.RegionDelegate;
import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.region.chunk.ChunkReader;
import com.terraforged.chunk.util.TerraContainer;
import com.terraforged.chunk.fix.RegionDelegate;
import me.dags.noise.Module;
import me.dags.noise.Source;
import me.dags.noise.util.NoiseUtil;

View File

@ -3,22 +3,43 @@ package com.terraforged.feature.decorator.poisson;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import com.terraforged.core.util.poisson.PoissonContext;
import me.dags.noise.Module;
import me.dags.noise.Source;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.placement.IPlacementConfig;
public class PoissonConfig implements IPlacementConfig {
public final int radius;
public final float biomeFade;
public final int variance;
public final float min;
public final float max;
public final int densityNoiseScale;
public final float densityNoiseMin;
public final float densityNoiseMax;
public PoissonConfig(int radius, float biomeFade, int variance, float min, float max) {
public PoissonConfig(int radius, float biomeFade, int densityNoiseScale, float densityNoiseMin, float densityNoiseMax) {
this.radius = radius;
this.biomeFade = biomeFade;
this.variance = variance;
this.min = min;
this.max = max;
this.densityNoiseScale = densityNoiseScale;
this.densityNoiseMin = densityNoiseMin;
this.densityNoiseMax = densityNoiseMax;
}
public void apply(IWorld world, PoissonContext context) {
Module fade = Source.ONE;
Module density = Source.ONE;
if (biomeFade > 0.075F) {
fade = BiomeVariance.of(world, biomeFade);
}
if (densityNoiseScale > 0) {
density = Source.simplex(context.seed, densityNoiseScale, 1)
.scale(densityNoiseMax - densityNoiseMin)
.bias(densityNoiseMin);
}
context.density = mult(fade, density);
}
@Override
@ -26,20 +47,30 @@ public class PoissonConfig implements IPlacementConfig {
return new Dynamic<>(ops, ops.createMap(
ImmutableMap.of(
ops.createString("radius"), ops.createInt(radius),
ops.createString("fade"), ops.createFloat(biomeFade),
ops.createString("scale"), ops.createInt(variance),
ops.createString("min"), ops.createFloat(min),
ops.createString("max"), ops.createFloat(max)
ops.createString("biome_fade"), ops.createFloat(biomeFade),
ops.createString("density_noise_scale"), ops.createInt(densityNoiseScale),
ops.createString("density_noise_min"), ops.createFloat(densityNoiseMin),
ops.createString("density_noise_max"), ops.createFloat(densityNoiseMax)
))
);
}
public static PoissonConfig deserialize(Dynamic<?> dynamic) {
int radius = dynamic.get("radius").asInt(4);
float biomeFade = dynamic.get("fade").asFloat(0.2F);
int variance = dynamic.get("scale").asInt(0);
float min = dynamic.get("min").asFloat(0F);
float max = dynamic.get("max").asFloat(1F);
float biomeFade = dynamic.get("biome_fade").asFloat(0.2F);
int variance = dynamic.get("density_noise_scale").asInt(0);
float min = dynamic.get("density_noise_min").asFloat(0F);
float max = dynamic.get("density_noise_max").asFloat(1F);
return new PoissonConfig(radius, biomeFade, variance, min, max);
}
private static Module mult(Module a, Module b) {
if (a == Source.ONE) {
return b;
}
if (b == Source.ONE) {
return a;
}
return a.mult(b);
}
}

View File

@ -1,9 +1,6 @@
package com.terraforged.feature.decorator.poisson;
import com.terraforged.core.util.poisson.Poisson;
import com.terraforged.core.util.poisson.PoissonContext;
import me.dags.noise.Module;
import me.dags.noise.Source;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.gen.ChunkGenerator;
@ -30,7 +27,7 @@ public abstract class PoissonDecorator extends Placement<PoissonConfig> {
int radius = Math.max(1, Math.min(30, config.radius));
Poisson poisson = getInstance(radius);
PoissonVisitor visitor = new PoissonVisitor(this, feature, world, generator, random, pos);
setVariance(world, visitor, config);
config.apply(world, visitor);
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
poisson.visit(chunkX, chunkZ, visitor, visitor);
@ -52,20 +49,4 @@ public abstract class PoissonDecorator extends Placement<PoissonConfig> {
return instance;
}
}
private void setVariance(IWorld world, PoissonContext context, PoissonConfig config) {
Module module = Source.ONE;
if (config.biomeFade > 0.075F) {
module = BiomeVariance.of(world, config.biomeFade);
}
if (config.variance > 0) {
module = module.mult(Source.simplex(context.seed, config.variance, 1)
.scale(config.max - config.min)
.bias(config.min));
}
context.density = module;
}
}

View File

@ -25,9 +25,9 @@
package com.terraforged.feature.predicate;
import com.terraforged.chunk.TerraContext;
import com.terraforged.fm.predicate.FeaturePredicate;
import com.terraforged.world.climate.Climate;
import com.terraforged.chunk.TerraContext;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.Heightmap;

View File

@ -2,10 +2,10 @@ package com.terraforged.feature.sapling;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.terraforged.feature.BlockDataConfig;
import com.terraforged.fm.template.TemplateManager;
import com.terraforged.fm.template.feature.TemplateFeatureConfig;
import com.terraforged.fm.util.Json;
import com.terraforged.feature.BlockDataConfig;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.util.ResourceLocation;

View File

@ -28,10 +28,10 @@ package com.terraforged.feature.sapling;
import com.terraforged.TerraWorld;
import com.terraforged.chunk.TerraChunkGenerator;
import com.terraforged.chunk.TerraContext;
import com.terraforged.feature.BlockDataManager;
import com.terraforged.fm.template.Template;
import com.terraforged.fm.template.feature.TemplateFeature;
import com.terraforged.fm.template.feature.TemplateFeatureConfig;
import com.terraforged.fm.template.Template;
import com.terraforged.feature.BlockDataManager;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.Mirror;

View File

@ -25,8 +25,8 @@
package com.terraforged.gui;
import com.terraforged.gui.preview.Preview;
import com.terraforged.gui.element.Element;
import com.terraforged.gui.preview.Preview;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.screen.Screen;

View File

@ -27,14 +27,14 @@ package com.terraforged.gui;
import com.terraforged.gui.element.TerraLabel;
import com.terraforged.gui.page.ClimatePage;
import com.terraforged.gui.page.Page;
import com.terraforged.gui.page.StructurePage;
import com.terraforged.gui.page.TerrainPage;
import com.terraforged.gui.preview.PreviewPage;
import com.terraforged.gui.page.MiscPage;
import com.terraforged.gui.page.Page;
import com.terraforged.gui.page.PresetsPage;
import com.terraforged.gui.page.RiverPage;
import com.terraforged.gui.page.StructurePage;
import com.terraforged.gui.page.TerrainPage;
import com.terraforged.gui.page.WorldPage;
import com.terraforged.gui.preview.PreviewPage;
import com.terraforged.settings.SettingsHelper;
import com.terraforged.settings.TerraSettings;
import com.terraforged.util.nbt.NBTHelper;

View File

@ -26,8 +26,8 @@
package com.terraforged.gui.page;
import com.terraforged.core.settings.Settings;
import com.terraforged.gui.preview.PreviewPage;
import com.terraforged.gui.OverlayScreen;
import com.terraforged.gui.preview.PreviewPage;
import com.terraforged.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT;

View File

@ -25,14 +25,14 @@
package com.terraforged.gui.page;
import com.terraforged.gui.element.TerraLabel;
import com.terraforged.gui.element.TerraSlider;
import com.terraforged.gui.element.TerraTextInput;
import com.terraforged.gui.element.TerraToggle;
import com.terraforged.gui.OverlayRenderer;
import com.terraforged.gui.OverlayScreen;
import com.terraforged.gui.ScrollPane;
import com.terraforged.gui.element.Element;
import com.terraforged.gui.element.TerraLabel;
import com.terraforged.gui.element.TerraSlider;
import com.terraforged.gui.element.TerraTextInput;
import com.terraforged.gui.element.TerraToggle;
import com.terraforged.util.nbt.NBTHelper;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.screen.Screen;

View File

@ -26,8 +26,8 @@
package com.terraforged.gui.page;
import com.terraforged.core.settings.Settings;
import com.terraforged.gui.preview.PreviewPage;
import com.terraforged.gui.OverlayScreen;
import com.terraforged.gui.preview.PreviewPage;
import com.terraforged.util.nbt.NBTHelper;
import net.minecraft.nbt.CompoundNBT;

View File

@ -28,12 +28,12 @@ package com.terraforged.gui.preview;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.concurrent.cache.CacheEntry;
import com.terraforged.core.concurrent.pool.ThreadPools;
import com.terraforged.core.region.Region;
import com.terraforged.core.region.Size;
import com.terraforged.core.region.gen.RegionGenerator;
import com.terraforged.core.settings.Settings;
import com.terraforged.core.concurrent.ThreadPool;
import com.terraforged.core.concurrent.cache.CacheEntry;
import com.terraforged.util.nbt.NBTHelper;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.continent.MutableVeci;
@ -203,7 +203,7 @@ public class Preview extends Button {
context.factory.getHeightmap().getContinent().getNearestCenter(offsetX, offsetZ, center);
RegionGenerator renderer = RegionGenerator.builder()
.pool(ThreadPool.getPool())
.pool(ThreadPools.getPool())
.size(FACTOR, 0)
.factory(context.factory)
.batch(6)

View File

@ -28,7 +28,7 @@ package com.terraforged.material;
import com.terraforged.api.material.WGTags;
import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.api.material.state.States;
import com.terraforged.core.concurrent.ObjectPool;
import com.terraforged.core.concurrent.Resource;
import com.terraforged.util.DummyBlockReader;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ObjectSets;
@ -98,9 +98,9 @@ public class Materials {
}
public static float getHardness(BlockState state) {
try (ObjectPool.Item<DummyBlockReader> reader = DummyBlockReader.pooled()) {
reader.getValue().set(state);
return state.getBlockHardness(reader.getValue(), BlockPos.ZERO);
try (Resource<DummyBlockReader> reader = DummyBlockReader.pooled()) {
reader.get().set(state);
return state.getBlockHardness(reader.get(), BlockPos.ZERO);
}
}
}

View File

@ -27,11 +27,11 @@ package com.terraforged.material.geology;
import com.terraforged.api.material.geology.GeologyManager;
import com.terraforged.api.material.geology.StrataConfig;
import com.terraforged.chunk.TerraContext;
import com.terraforged.core.Seed;
import com.terraforged.material.Materials;
import com.terraforged.world.geology.Geology;
import com.terraforged.world.geology.Strata;
import com.terraforged.chunk.TerraContext;
import com.terraforged.material.Materials;
import me.dags.noise.Module;
import me.dags.noise.Source;
import net.minecraft.block.BlockState;

View File

@ -1,9 +1,9 @@
package com.terraforged.settings;
import com.terraforged.TerraWorld;
import com.terraforged.core.serialization.annotation.Comment;
import com.terraforged.core.serialization.annotation.Range;
import com.terraforged.core.serialization.annotation.Serializable;
import com.terraforged.TerraWorld;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.StringNBT;
import net.minecraft.world.WorldType;

View File

@ -25,8 +25,8 @@
package com.terraforged.settings;
import com.terraforged.core.settings.Settings;
import com.terraforged.core.serialization.annotation.Serializable;
import com.terraforged.core.settings.Settings;
@Serializable
public class TerraSettings extends Settings {

View File

@ -26,6 +26,7 @@
package com.terraforged.util;
import com.terraforged.core.concurrent.ObjectPool;
import com.terraforged.core.concurrent.Resource;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.fluid.FluidState;
@ -74,7 +75,7 @@ public class DummyBlockReader implements IBlockReader {
return fluid;
}
public static ObjectPool.Item<DummyBlockReader> pooled() {
public static Resource<DummyBlockReader> pooled() {
return pool.get();
}
}

View File

@ -2,34 +2,36 @@ package com.terraforged.util;
public abstract class RangeModifier {
protected final float min;
protected final float from;
protected final float to;
protected final float max;
private final float range;
public RangeModifier(float min, float max) {
this.min = min;
this.max = max;
this.range = Math.abs(max - min);
public RangeModifier(float from, float max, boolean exclusive) {
this.from = from;
this.to = max;
this.max = exclusive ? 0 : 1;
this.range = Math.abs(max - from);
}
public float apply(float value) {
if (min < max) {
if (value <= min) {
if (from < to) {
if (value <= from) {
return 0F;
}
if (value >= max) {
return 1F;
if (value >= to) {
return max;
}
return (value - min) / range;
} else if (min > max) {
if (value <= min) {
return 1F;
return (value - from) / range;
} else if (from > to) {
if (value <= to) {
return max;
}
if (value >= max) {
if (value >= from) {
return 0F;
}
return 1F - (value / range);
return 1 - ((value - to) / range);
}
return 1F;
return 0F;
}
}

View File

@ -25,8 +25,8 @@
package com.terraforged.util.setup;
import com.terraforged.api.event.SetupEvent;
import com.terraforged.Log;
import com.terraforged.api.event.SetupEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

View File

@ -32,8 +32,8 @@ import com.terraforged.api.chunk.surface.SurfaceManager;
import com.terraforged.api.event.SetupEvent;
import com.terraforged.api.material.geology.GeologyManager;
import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.fm.structure.StructureManager;
import com.terraforged.fm.modifier.FeatureModifiers;
import com.terraforged.fm.structure.StructureManager;
import com.terraforged.world.GeneratorContext;
import com.terraforged.world.terrain.provider.TerrainProvider;
import net.minecraftforge.common.MinecraftForge;

View File

@ -43,10 +43,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 9,
"fade": 0.25,
"scale": 300,
"min": 0,
"max": 2
"biome_fade": 0.25,
"density_noise_scale": 300,
"density_noise_min": 0,
"density_noise_max": 2
}
}
}

View File

@ -58,10 +58,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 8,
"fade": 0.35,
"scale": 300,
"min": 0,
"max": 2
"biome_fade": 0.35,
"density_noise_scale": 300,
"density_noise_min": 0,
"density_noise_max": 2
}
}
}

View File

@ -127,10 +127,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 8,
"fade": 0.4,
"scale": 200,
"min": 0,
"max": 1.85
"biome_fade": 0.4,
"density_noise_scale": 200,
"density_noise_min": 0,
"density_noise_max": 1.85
}
}
}

View File

@ -25,10 +25,10 @@
}
},
"context": {
"chance": 0.2,
"chance": 0.1,
"elevation": {
"min": 0.75,
"max": 0.25
"from": 0.55,
"to": 0.2
}
}
},
@ -40,10 +40,14 @@
}
},
"context": {
"chance": 0.2,
"chance": 0.25,
"elevation": {
"min": 0.5,
"max": 0.0
"from": 0.3,
"to": 0.0
},
"biome": {
"from": 0,
"to": 0.2
}
}
}
@ -53,11 +57,11 @@
"decorator": {
"name": "terraforged:poisson_surface",
"config": {
"radius": 6,
"fade": 0.3,
"scale": 200,
"min": 0,
"max": 2.5
"radius": 7,
"biome_fade": 0.3,
"density_noise_scale": 300,
"density_noise_min": 0,
"density_noise_max": 2.5
}
}
}

View File

@ -58,10 +58,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 15,
"fade": 0.3,
"scale": 500,
"min": 0.75,
"max": 2
"biome_fade": 0.3,
"density_noise_scale": 500,
"density_noise_min": 0.75,
"density_noise_max": 2
}
}
}

View File

@ -77,10 +77,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 6,
"fade": 0.2,
"scale": 400,
"min": 0.25,
"max": 2
"biome_fade": 0.2,
"density_noise_scale": 400,
"density_noise_min": 0.25,
"density_noise_max": 2
}
}
}

View File

@ -42,10 +42,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 9,
"fade": 0.3,
"scale": 350,
"min": 0.75,
"max": 1.5
"biome_fade": 0.3,
"density_noise_scale": 350,
"density_noise_min": 0.75,
"density_noise_max": 1.5
}
}
}

View File

@ -76,10 +76,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 8,
"fade": 0.2,
"scale": 200,
"min": 0.35,
"max": 1.85
"biome_fade": 0.2,
"density_noise_scale": 200,
"density_noise_min": 0.35,
"density_noise_max": 1.85
}
}
}

View File

@ -42,9 +42,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 9,
"scale": 150,
"min": 0.15,
"max": 1.75
"biome_fade": 0.2,
"density_noise_scale": 150,
"density_noise_min": 0.15,
"density_noise_max": 1.75
}
}
}

View File

@ -38,10 +38,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 10,
"fade": 0.25,
"scale": 250,
"min": 0.0,
"max": 2.75
"biome_fade": 0.25,
"density_noise_scale": 250,
"density_noise_min": 0.0,
"density_noise_max": 2.75
}
}
}

View File

@ -11,47 +11,88 @@
"name": "minecraft:decorated",
"config": {
"feature": {
"name": "minecraft:random_selector",
"name": "terraforged:context_selector",
"config": {
"features": [
{
"feature": {
"name": "terraforged:template",
"config": {
"template": "terraforged:redwood_huge"
},
"chance": 0.025641026
},
{
"name": "terraforged:template",
"config": {
"template": "terraforged:pine"
},
"chance": 0.15
},
{
"name": "terraforged:template",
"config": {
"template": "terraforged:redwood_large"
},
"chance": 0.33333334
}
],
"default": {
},
"context": {
"chance": 0.4,
"elevation": {
"from": 0.15,
"to": 0.0
},
"biome": {
"from": 0.1,
"to": 0.4
}
}
},
{
"feature": {
"name": "terraforged:template",
"config": {
"template": "terraforged:redwood_large"
}
},
"context": {
"chance": 0.2,
"elevation": {
"from": 0.25,
"to": 0.0
}
},
"biome": {
"from": 0.0,
"to": 0.25
}
},
{
"feature": {
"name": "terraforged:template",
"config": {
"template": "terraforged:spruce_large"
}
},
"context": {
"chance": 0.4,
"elevation": {
"from": 0.35,
"to": 0.15
}
}
},
{
"feature": {
"name": "terraforged:template",
"config": {
"template": "terraforged:spruce_small"
}
},
"context": {
"chance": 0.2,
"elevation": {
"from": 0.50,
"to": 0.2
}
}
}
]
}
},
"decorator": {
"name": "terraforged:poisson_surface",
"config": {
"radius": 9,
"fade": 0.2,
"scale": 250,
"min": 0.15,
"max": 2.25
"radius": 8,
"biome_fade": 0.2,
"density_noise_scale": 250,
"density_noise_min": 0.15,
"density_noise_max": 2.25
}
}
}

View File

@ -38,10 +38,10 @@
"name": "terraforged:poisson_surface",
"config": {
"radius": 10,
"fade": 0.3,
"scale": 250,
"min": 0.15,
"max": 1.75
"biome_fade": 0.3,
"density_noise_scale": 250,
"density_noise_min": 0.15,
"density_noise_max": 1.75
}
}
}

View File

@ -0,0 +1,59 @@
{
"biomes": [
"minecraft:*"
],
"match": [
[
"minecraft:mega_spruce_tree"
]
],
"replace": {
"name": "minecraft:decorated",
"config": {
"feature": {
"name": "minecraft:random_selector",
"config": {
"features": [
{
"name": "terraforged:template",
"config": {
"template": "terraforged:redwood_huge"
},
"chance": 0.025641026
},
{
"name": "terraforged:template",
"config": {
"template": "terraforged:pine"
},
"chance": 0.15
},
{
"name": "terraforged:template",
"config": {
"template": "terraforged:redwood_large"
},
"chance": 0.33333334
}
],
"default": {
"name": "terraforged:template",
"config": {
"template": "terraforged:redwood_large"
}
}
}
},
"decorator": {
"name": "terraforged:poisson_surface",
"config": {
"radius": 9,
"biome_fade": 0.2,
"density_noise_scale": 250,
"density_noise_min": 0.15,
"density_noise_max": 2.25
}
}
}
}
}