From 8d2e2f2f6efde0f415288150c3e558fefc3ceb32 Mon Sep 17 00:00:00 2001 From: dags- Date: Tue, 25 Feb 2020 23:16:30 +0000 Subject: [PATCH] separate api source from mod source --- FeatureManager | 2 +- TerraForgedAPI/build.gradle | 33 ++ TerraForgedAPI/gradle.properties | 7 + .../com/terraforged/api/biome/BiomeTags.java | 121 ++++++ .../modifier/AbstractMaxHeightModifier.java | 67 ++++ .../modifier/AbstractOffsetModifier.java | 49 +++ .../api/biome/modifier/BiomeModifier.java | 45 +++ .../modifier/BiomeModifierRegistrar.java | 31 ++ .../terraforged/api/chunk/ChunkContext.java | 48 +++ .../terraforged/api/chunk/ChunkDelegate.java | 347 ++++++++++++++++++ .../api/chunk/ChunkSurfaceBuffer.java | 67 ++++ .../api/chunk/column/ColumnDecorator.java | 60 +++ .../api/chunk/column/DecoratorManager.java | 47 +++ .../api/chunk/column/ProcessorContext.java | 52 +++ .../api/chunk/surface/CachedSurface.java | 34 ++ .../api/chunk/surface/Surface.java | 55 +++ .../api/chunk/surface/SurfaceContext.java | 53 +++ .../api/chunk/surface/SurfaceManager.java | 60 +++ .../api/chunk/surface/builder/Combiner.java | 46 +++ .../api/chunk/surface/builder/Delegate.java | 67 ++++ .../com/terraforged/api/event/TerraEvent.java | 109 ++++++ .../api/material/MaterialTags.java | 49 +++ .../api/material/geology/GeologyManager.java | 58 +++ .../api/material/geology/StrataConfig.java | 64 ++++ .../api/material/geology/StrataGenerator.java | 34 ++ .../api/material/layer/LayerManager.java | 53 +++ .../api/material/layer/LayerMaterial.java | 135 +++++++ .../api/material/state/CachedState.java | 65 ++++ .../api/material/state/DefaultState.java | 62 ++++ .../api/material/state/StateSupplier.java | 42 +++ .../api/material/state/States.java | 44 +++ .../terraforged/app/renderer/Renderer.java | 3 + .../core/settings/FilterSettings.java | 8 +- TerraForgedMod | 2 +- settings.gradle | 5 +- 35 files changed, 2016 insertions(+), 8 deletions(-) create mode 100644 TerraForgedAPI/build.gradle create mode 100644 TerraForgedAPI/gradle.properties create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeTags.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifierRegistrar.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkContext.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkDelegate.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkSurfaceBuffer.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ProcessorContext.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/CachedSurface.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceManager.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Combiner.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Delegate.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/event/TerraEvent.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/MaterialTags.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/GeologyManager.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataConfig.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerManager.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/state/CachedState.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/state/DefaultState.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateSupplier.java create mode 100644 TerraForgedAPI/src/main/java/com/terraforged/api/material/state/States.java diff --git a/FeatureManager b/FeatureManager index c8448a4..a53367b 160000 --- a/FeatureManager +++ b/FeatureManager @@ -1 +1 @@ -Subproject commit c8448a4425de149fc5e0ac189cea757fe2ba0772 +Subproject commit a53367b857a43107877096869c40d53fa16fd216 diff --git a/TerraForgedAPI/build.gradle b/TerraForgedAPI/build.gradle new file mode 100644 index 0000000..a75e309 --- /dev/null +++ b/TerraForgedAPI/build.gradle @@ -0,0 +1,33 @@ +buildscript { + repositories { + jcenter() + mavenCentral() + maven { url "https://files.minecraftforge.net/maven" } + } + dependencies { + classpath group: "net.minecraftforge.gradle", name: "ForgeGradle", version: "3.+", changing: true + } +} + +apply plugin: "net.minecraftforge.gradle" +apply plugin: "eclipse" +apply plugin: "maven" + +version = "${version}-mc${mc_version}" +archivesBaseName = "TerraForgedAPI" + +repositories { + jcenter() + mavenCentral() +} + +dependencies { + minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}" + compile project(":Noise2D") + compile project(":FeatureManager") + compile project(":TerraForgedCore") +} + +minecraft { + mappings channel: mcp_channel, version: mcp_version +} \ No newline at end of file diff --git a/TerraForgedAPI/gradle.properties b/TerraForgedAPI/gradle.properties new file mode 100644 index 0000000..42ae501 --- /dev/null +++ b/TerraForgedAPI/gradle.properties @@ -0,0 +1,7 @@ +mod_version=0.0.1-ALPHA +mc_version=1.15.2 +forge_version=31.0.1 +mcp_channel=snapshot +mcp_version=20200124-1.15.1 +org.gradle.jvmargs=-Xmx8G +org.gradle.daemon=false \ No newline at end of file diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeTags.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeTags.java new file mode 100644 index 0000000..e411af3 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/BiomeTags.java @@ -0,0 +1,121 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.biome; + +import com.terraforged.core.world.biome.BiomeType; +import net.minecraft.tags.Tag; +import net.minecraft.tags.TagCollection; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; + +import java.util.Collection; +import java.util.EnumMap; +import java.util.Map; +import java.util.Optional; + +public class BiomeTags { + + private static int generation; + private static TagCollection collection = new TagCollection<>( + path -> Optional.empty(), + "", + false, + "" + ); + + private static final Map tags = new EnumMap<>(BiomeType.class); + + public static final Tag ALPINE = tag(BiomeType.ALPINE); + public static final Tag COLD_STEPPE = tag(BiomeType.COLD_STEPPE); + public static final Tag DESERT = tag(BiomeType.DESERT); + public static final Tag GRASSLAND = tag(BiomeType.GRASSLAND); + public static final Tag SAVANNA = tag(BiomeType.SAVANNA); + public static final Tag STEPPE = tag(BiomeType.STEPPE); + public static final Tag TAIGA = tag(BiomeType.TAIGA); + public static final Tag TEMPERATE_FOREST = tag(BiomeType.TEMPERATE_FOREST); + public static final Tag TEMPERATE_RAINFOREST = tag(BiomeType.TEMPERATE_RAINFOREST); + public static final Tag TROPICAL_RAINFOREST = tag(BiomeType.TROPICAL_RAINFOREST); + public static final Tag TUNDRA = tag(BiomeType.TUNDRA); + + public static Tag getTag(BiomeType type) { + return tags.get(type); + } + + public static void setCollection(TagCollection collection) { + BiomeTags.collection = collection; + BiomeTags.generation++; + } + + private static BiomeWrapper tag(BiomeType type) { + BiomeWrapper wrapper = tag(type.name().toLowerCase()); + tags.put(type, wrapper); + return wrapper; + } + + private static BiomeWrapper tag(String name) { + return new BiomeWrapper(new ResourceLocation("terraforged", name)); + } + + private static class BiomeWrapper extends Tag { + + private Tag cachedTag = null; + private int lastKnownGeneration = -1; + + public BiomeWrapper(ResourceLocation name) { + super(name); + } + + @Override + public boolean contains(Biome biome) { + if (this.lastKnownGeneration != BiomeTags.generation) { + this.cachedTag = BiomeTags.collection.getOrCreate(this.getId()); + this.lastKnownGeneration = BiomeTags.generation; + } + + return this.cachedTag.contains(biome); + } + + @Override + public Collection getAllElements() { + if (this.lastKnownGeneration != BiomeTags.generation) { + this.cachedTag = BiomeTags.collection.getOrCreate(this.getId()); + this.lastKnownGeneration = BiomeTags.generation; + } + + return this.cachedTag.getAllElements(); + } + + @Override + public Collection> getEntries() { + if (this.lastKnownGeneration != BiomeTags.generation) { + this.cachedTag = BiomeTags.collection.getOrCreate(this.getId()); + this.lastKnownGeneration = BiomeTags.generation; + } + + return this.cachedTag.getEntries(); + } + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java new file mode 100644 index 0000000..773b321 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractMaxHeightModifier.java @@ -0,0 +1,67 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.biome.modifier; + +import com.terraforged.core.cell.Cell; +import com.terraforged.core.util.Seed; +import com.terraforged.core.world.climate.Climate; +import com.terraforged.core.world.terrain.Terrain; +import me.dags.noise.Module; +import me.dags.noise.Source; +import net.minecraft.world.biome.Biome; + +public abstract class AbstractMaxHeightModifier extends AbstractOffsetModifier { + + private final float minHeight; + private final float maxHeight; + private final float range; + private final Module variance; + + public AbstractMaxHeightModifier(Seed seed, Climate climate, int scale, int octaves, float variance, float minHeight, float maxHeight) { + super(climate); + this.minHeight = minHeight; + this.maxHeight = maxHeight; + this.range = maxHeight - minHeight; + this.variance = Source.perlin(seed.next(), scale, octaves).scale(variance); + } + + @Override + protected final Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz) { + float var = variance.getValue(x, z); + float value = cell.value + var; + if (value < minHeight) { + return in; + } + if (value > maxHeight) { + return getModifiedBiome(in, cell, x, z, ox, oz); + } + float alpha = (value - minHeight) / range; + cell.biomeEdge *= alpha; + return in; + } + + protected abstract Biome getModifiedBiome(Biome in, Cell cell, int x, int z, float ox, float oz); +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java new file mode 100644 index 0000000..d0a6a43 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/AbstractOffsetModifier.java @@ -0,0 +1,49 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.biome.modifier; + +import com.terraforged.core.cell.Cell; +import com.terraforged.core.world.climate.Climate; +import com.terraforged.core.world.terrain.Terrain; +import net.minecraft.world.biome.Biome; + +public abstract class AbstractOffsetModifier implements BiomeModifier { + + private final Climate climate; + + public AbstractOffsetModifier(Climate climate) { + this.climate = climate; + } + + @Override + public Biome modify(Biome in, Cell cell, int x, int z) { + float dx = climate.getOffsetX(x, z, 50); + float dz = climate.getOffsetX(x, z, 50); + return modify(in, cell, x, z, x + dx, z + dz); + } + + protected abstract Biome modify(Biome in, Cell cell, int x, int z, float ox, float oz); +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java new file mode 100644 index 0000000..2d81330 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifier.java @@ -0,0 +1,45 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.biome.modifier; + +import com.terraforged.core.cell.Cell; +import com.terraforged.core.world.terrain.Terrain; +import net.minecraft.world.biome.Biome; + +public interface BiomeModifier extends Comparable { + + int priority(); + + boolean test(Biome biome); + + Biome modify(Biome in, Cell cell, int x, int z); + + @Override + default int compareTo(BiomeModifier other) { + // reverse order + return Integer.compare(other.priority(), priority()); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifierRegistrar.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifierRegistrar.java new file mode 100644 index 0000000..6193137 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifierRegistrar.java @@ -0,0 +1,31 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.biome.modifier; + +public interface BiomeModifierRegistrar { + + +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkContext.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkContext.java new file mode 100644 index 0000000..e1afd9b --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkContext.java @@ -0,0 +1,48 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk; + +import net.minecraft.util.SharedSeedRandom; +import net.minecraft.world.chunk.IChunk; + +public class ChunkContext { + + public final int chunkX; + public final int chunkZ; + public final int blockX; + public final int blockZ; + public final IChunk chunk; + public final SharedSeedRandom random = new SharedSeedRandom(); + + public ChunkContext(IChunk chunk) { + this.chunk = chunk; + this.chunkX = chunk.getPos().x; + this.chunkZ = chunk.getPos().z; + this.blockX = chunkX << 4; + this.blockZ = chunkZ << 4; + this.random.setBaseChunkSeed(chunkX, chunkZ); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkDelegate.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkDelegate.java new file mode 100644 index 0000000..a4fc441 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkDelegate.java @@ -0,0 +1,347 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk; + +import it.unimi.dsi.fastutil.longs.LongSet; +import it.unimi.dsi.fastutil.shorts.ShortList; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.IFluidState; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.RayTraceContext; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.palette.UpgradeData; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.ITickList; +import net.minecraft.world.IWorld; +import net.minecraft.world.biome.BiomeContainer; +import net.minecraft.world.chunk.ChunkSection; +import net.minecraft.world.chunk.ChunkStatus; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.GenerationStage; +import net.minecraft.world.gen.Heightmap; +import net.minecraft.world.gen.feature.structure.StructureStart; + +import javax.annotation.Nullable; +import java.util.BitSet; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Stream; + +public class ChunkDelegate implements IChunk { + + private final IChunk chunk; + + public ChunkDelegate(IChunk chunk) { + this.chunk = chunk; + } + + public IChunk getChunk() { + return chunk; + } + + @Override + @Nullable + public BlockState setBlockState(BlockPos pos, BlockState state, boolean isMoving) { + return chunk.setBlockState(pos, state, isMoving); + } + + @Override + public void addTileEntity(BlockPos pos, TileEntity tileEntityIn) { + chunk.addTileEntity(pos, tileEntityIn); + } + + @Override + public void addEntity(Entity entityIn) { + chunk.addEntity(entityIn); + } + + @Override + @Nullable + public ChunkSection getLastExtendedBlockStorage() { + return chunk.getLastExtendedBlockStorage(); + } + + @Override + public int getTopFilledSegment() { + return chunk.getTopFilledSegment(); + } + + @Override + public Set getTileEntitiesPos() { + return chunk.getTileEntitiesPos(); + } + + @Override + public ChunkSection[] getSections() { + return chunk.getSections(); + } + + @Override + public Collection> getHeightmaps() { + return chunk.getHeightmaps(); + } + + @Override + public void setHeightmap(Heightmap.Type type, long[] data) { + chunk.setHeightmap(type, data); + } + + @Override + public Heightmap getHeightmap(Heightmap.Type type) { + return chunk.getHeightmap(type); + } + + @Override + public int getTopBlockY(Heightmap.Type heightmapType, int x, int z) { + return chunk.getTopBlockY(heightmapType, x, z); + } + + @Override + public ChunkPos getPos() { + return chunk.getPos(); + } + + @Override + public void setLastSaveTime(long saveTime) { + chunk.setLastSaveTime(saveTime); + } + + @Override + public Map getStructureStarts() { + return chunk.getStructureStarts(); + } + + @Override + public void setStructureStarts(Map structureStartsIn) { + chunk.setStructureStarts(structureStartsIn); + } + + @Override + public boolean isEmptyBetween(int startY, int endY) { + return chunk.isEmptyBetween(startY, endY); + } + + @Override + @Nullable + public BiomeContainer getBiomes() { + return chunk.getBiomes(); + } + + @Override + public void setModified(boolean modified) { + chunk.setModified(modified); + } + + @Override + public boolean isModified() { + return chunk.isModified(); + } + + @Override + public ChunkStatus getStatus() { + return chunk.getStatus(); + } + + @Override + public void removeTileEntity(BlockPos pos) { + chunk.removeTileEntity(pos); + } + + @Override + public void markBlockForPostprocessing(BlockPos pos) { + chunk.markBlockForPostprocessing(pos); + } + + @Override + public ShortList[] getPackedPositions() { + return chunk.getPackedPositions(); + } + + @Override + public void func_201636_b(short packedPosition, int index) { + chunk.func_201636_b(packedPosition, index); + } + + @Override + public void addTileEntity(CompoundNBT nbt) { + chunk.addTileEntity(nbt); + } + + @Override + @Nullable + public CompoundNBT getDeferredTileEntity(BlockPos pos) { + return chunk.getDeferredTileEntity(pos); + } + + @Override + @Nullable + public CompoundNBT getTileEntityNBT(BlockPos pos) { + return chunk.getTileEntityNBT(pos); + } + + @Override + public Stream getLightSources() { + return chunk.getLightSources(); + } + + @Override + public ITickList getBlocksToBeTicked() { + return chunk.getBlocksToBeTicked(); + } + + @Override + public ITickList getFluidsToBeTicked() { + return chunk.getFluidsToBeTicked(); + } + + @Override + public BitSet getCarvingMask(GenerationStage.Carving type) { + return chunk.getCarvingMask(type); + } + + @Override + public UpgradeData getUpgradeData() { + return chunk.getUpgradeData(); + } + + @Override + public void setInhabitedTime(long newInhabitedTime) { + chunk.setInhabitedTime(newInhabitedTime); + } + + @Override + public long getInhabitedTime() { + return chunk.getInhabitedTime(); + } + + public static ShortList getList(ShortList[] p_217308_0_, int p_217308_1_) { + return IChunk.getList(p_217308_0_, p_217308_1_); + } + + @Override + public boolean hasLight() { + return chunk.hasLight(); + } + + @Override + public void setLight(boolean p_217305_1_) { + chunk.setLight(p_217305_1_); + } + + @Override + @Nullable + public IWorld getWorldForge() { + return chunk.getWorldForge(); + } + + @Override + @Nullable + public TileEntity getTileEntity(BlockPos pos) { + return chunk.getTileEntity(pos); + } + + @Override + public BlockState getBlockState(BlockPos pos) { + return chunk.getBlockState(pos); + } + + @Override + public IFluidState getFluidState(BlockPos pos) { + return chunk.getFluidState(pos); + } + + @Override + public int getLightValue(BlockPos pos) { + return chunk.getLightValue(pos); + } + + @Override + public int getMaxLightLevel() { + return chunk.getMaxLightLevel(); + } + + @Override + public int getHeight() { + return chunk.getHeight(); + } + + @Override + public BlockRayTraceResult rayTraceBlocks(RayTraceContext context) { + return chunk.rayTraceBlocks(context); + } + + @Override + @Nullable + public BlockRayTraceResult rayTraceBlocks(Vec3d p_217296_1_, Vec3d p_217296_2_, BlockPos p_217296_3_, VoxelShape p_217296_4_, BlockState p_217296_5_) { + return chunk.rayTraceBlocks(p_217296_1_, p_217296_2_, p_217296_3_, p_217296_4_, p_217296_5_); + } + + public static T func_217300_a(RayTraceContext p_217300_0_, BiFunction p_217300_1_, Function p_217300_2_) { + return IBlockReader.func_217300_a(p_217300_0_, p_217300_1_, p_217300_2_); + } + + @Override + @Nullable + public StructureStart getStructureStart(String stucture) { + return chunk.getStructureStart(stucture); + } + + @Override + public void putStructureStart(String structureIn, StructureStart structureStartIn) { + chunk.putStructureStart(structureIn, structureStartIn); + } + + @Override + public LongSet getStructureReferences(String structureIn) { + return chunk.getStructureReferences(structureIn); + } + + @Override + public void addStructureReference(String strucutre, long reference) { + chunk.addStructureReference(strucutre, reference); + } + + @Override + public Map getStructureReferences() { + return chunk.getStructureReferences(); + } + + @Override + public void setStructureReferences(Map p_201606_1_) { + chunk.setStructureReferences(p_201606_1_); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkSurfaceBuffer.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkSurfaceBuffer.java new file mode 100644 index 0000000..b0e5eb9 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/ChunkSurfaceBuffer.java @@ -0,0 +1,67 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk; + +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.IChunk; + +import javax.annotation.Nullable; + +public class ChunkSurfaceBuffer extends ChunkDelegate { + + private int surfaceTop; + private int surfaceBottom; + + public ChunkSurfaceBuffer(IChunk chunk) { + super(chunk); + } + + @Nullable + @Override + public BlockState setBlockState(BlockPos pos, BlockState state, boolean isMoving) { + if (pos.getY() > surfaceTop) { + surfaceTop = pos.getY(); + } + if (pos.getY() < surfaceBottom) { + surfaceBottom = pos.getY(); + } + return super.setBlockState(pos, state, isMoving); + } + + public int getSurfaceTop() { + return surfaceTop; + } + + public int getSurfaceBottom() { + return surfaceBottom; + } + + public void setSurfaceLevel(int y) { + surfaceTop = y; + surfaceBottom = y; + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java new file mode 100644 index 0000000..421238f --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java @@ -0,0 +1,60 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.column; + +import com.terraforged.api.chunk.ChunkSurfaceBuffer; +import me.dags.noise.Source; +import me.dags.noise.source.FastSource; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.IChunk; + +public interface ColumnDecorator { + + FastSource variance = (FastSource) Source.perlin(0, 100, 1); + ThreadLocal pos = ThreadLocal.withInitial(BlockPos.Mutable::new); + ThreadLocal pos1 = ThreadLocal.withInitial(BlockPos.Mutable::new); + + void decorate(IChunk chunk, ProcessorContext context, int x, int y, int z); + + default void decorate(ChunkSurfaceBuffer buffer, ProcessorContext context, int x, int y, int z) { + decorate(buffer.getChunk(), context, x, y, z); + } + + default void fillDown(IChunk chunk, int x, int z, int from, int to, BlockState state) { + for (int dy = from; dy > to; dy--) { + chunk.setBlockState(pos.get().setPos(x, dy, z), state, false); + } + } + + static float getNoise(float x, float z, int seed, float scale, float bias) { + return (variance.getValue(x, z, seed) * scale) + bias; + } + + static float getNoise(float x, float z, int seed, int scale, int bias) { + return getNoise(x, z, seed, scale / 255F, bias / 255F); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java new file mode 100644 index 0000000..81671ea --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorManager.java @@ -0,0 +1,47 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.column; + +import java.util.List; + +public class DecoratorManager { + + private final List baseDecorators; + private final List featureDecorators; + + public DecoratorManager(List baseDecorators, List featureDecorators) { + this.baseDecorators = baseDecorators; + this.featureDecorators = featureDecorators; + } + + public void registerBaseDecorator(ColumnDecorator decorator) { + baseDecorators.add(decorator); + } + + public void registerFeatureDecorator(ColumnDecorator decorator) { + featureDecorators.add(decorator); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ProcessorContext.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ProcessorContext.java new file mode 100644 index 0000000..906bff5 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ProcessorContext.java @@ -0,0 +1,52 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.column; + +import com.terraforged.api.chunk.ChunkContext; +import com.terraforged.core.cell.Cell; +import com.terraforged.core.world.climate.Climate; +import com.terraforged.core.world.heightmap.Levels; +import com.terraforged.core.world.terrain.Terrain; +import com.terraforged.core.world.terrain.Terrains; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.IChunk; + +public class ProcessorContext extends ChunkContext { + + public final Levels levels; + public final Climate climate; + public final Terrains terrains; + + public Biome biome; + public Cell cell; + + public ProcessorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate) { + super(chunk); + this.levels = levels; + this.climate = climate; + this.terrains = terrain; + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/CachedSurface.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/CachedSurface.java new file mode 100644 index 0000000..8bda7b8 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/CachedSurface.java @@ -0,0 +1,34 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.surface; + +import net.minecraft.world.biome.Biome; + +public class CachedSurface { + + public Biome biome; + public Surface surface; +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java new file mode 100644 index 0000000..50880f8 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java @@ -0,0 +1,55 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.surface; + + +import com.terraforged.api.chunk.surface.builder.Combiner; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.IChunk; + +public interface Surface { + + BlockPos.Mutable pos = new BlockPos.Mutable(); + + void buildSurface(int x, int z, int height, SurfaceContext ctx); + + default void fill(int x, int z, int start, int end, IChunk chunk, BlockState state) { + if (start < end) { + for (int y = start; y < end; y++) { + chunk.setBlockState(pos.setPos(x, y, z), state, false); + } + } else if (start > end) { + for (int y = start; y > end; y--) { + chunk.setBlockState(pos.setPos(x, y, z), state, false); + } + } + } + + default Surface then(Surface next) { + return new Combiner(this, next); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java new file mode 100644 index 0000000..fd92813 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java @@ -0,0 +1,53 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.surface; + +import com.terraforged.api.chunk.column.ProcessorContext; +import com.terraforged.core.world.climate.Climate; +import com.terraforged.core.world.heightmap.Levels; +import com.terraforged.core.world.terrain.Terrains; +import net.minecraft.block.BlockState; +import net.minecraft.world.chunk.IChunk; +import net.minecraft.world.gen.GenerationSettings; + +public class SurfaceContext extends ProcessorContext { + + public final BlockState solid; + public final BlockState fluid; + public final int seaLevel; + public final long seed; + public final CachedSurface cached = new CachedSurface(); + + public double noise; + + public SurfaceContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate, GenerationSettings settings, long seed) { + super(chunk, levels, terrain, climate); + this.solid = settings.getDefaultBlock(); + this.fluid = settings.getDefaultFluid(); + this.seed = seed; + this.seaLevel = levels.waterLevel; + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceManager.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceManager.java new file mode 100644 index 0000000..e0578de --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceManager.java @@ -0,0 +1,60 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.surface; + +import com.terraforged.api.chunk.surface.builder.Delegate; +import net.minecraft.world.biome.Biome; + +import java.util.HashMap; +import java.util.Map; + +public class SurfaceManager { + + private final Map surfaces = new HashMap<>(); + + public SurfaceManager replace(Biome biome, Surface surface) { + surfaces.put(biome, surface); + return this; + } + + public SurfaceManager extend(Biome biome, Surface surface) { + Surface result = getOrCreateSurface(biome).then(surface); + return replace(biome, result); + } + + public Surface getSurface(SurfaceContext context) { + if (context.biome == context.cached.biome) { + return context.cached.surface; + } + context.cached.biome = context.biome; + context.cached.surface = getOrCreateSurface(context.biome); + return context.cached.surface; + } + + public Surface getOrCreateSurface(Biome biome) { + return surfaces.computeIfAbsent(biome, Delegate.FUNC); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Combiner.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Combiner.java new file mode 100644 index 0000000..fdc7015 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Combiner.java @@ -0,0 +1,46 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.surface.builder; + +import com.terraforged.api.chunk.surface.Surface; +import com.terraforged.api.chunk.surface.SurfaceContext; + +public class Combiner implements Surface { + + private final Surface first; + private final Surface second; + + public Combiner(Surface first, Surface second) { + this.first = first; + this.second = second; + } + + @Override + public void buildSurface(int x, int z, int height, SurfaceContext ctx) { + first.buildSurface(x, z, height, ctx); + second.buildSurface(x, z, height, ctx); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Delegate.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Delegate.java new file mode 100644 index 0000000..2f9034d --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/builder/Delegate.java @@ -0,0 +1,67 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.chunk.surface.builder; + +import com.terraforged.api.chunk.surface.Surface; +import com.terraforged.api.chunk.surface.SurfaceContext; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.surfacebuilders.ConfiguredSurfaceBuilder; + +import java.util.function.Function; + +public class Delegate implements Surface { + + public static final Function FUNC = Delegate::new; + + private final ConfiguredSurfaceBuilder surfaceBuilder; + + private Delegate(Biome biome) { + this(biome.getSurfaceBuilder()); + } + + private Delegate(ConfiguredSurfaceBuilder surfaceBuilder) { + this.surfaceBuilder = surfaceBuilder; + } + + @Override + public void buildSurface(int x, int z, int height, SurfaceContext context) { + surfaceBuilder.setSeed(context.seed); + + surfaceBuilder.buildSurface( + context.random, + context.chunk, + context.biome, + x, + z, + height, + context.noise, + context.solid, + context.fluid, + context.seaLevel, + context.seed + ); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/event/TerraEvent.java b/TerraForgedAPI/src/main/java/com/terraforged/api/event/TerraEvent.java new file mode 100644 index 0000000..6e4fbc0 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/event/TerraEvent.java @@ -0,0 +1,109 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.event; + +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.core.world.terrain.provider.TerrainProvider; +import com.terraforged.feature.modifier.FeatureModifiers; +import net.minecraftforge.eventbus.api.Event; + +public abstract class TerraEvent extends Event { + + private final T manager; + + public TerraEvent(T manager) { + this.manager = manager; + } + + public T getManager() { + return manager; + } + + /** + * Can be used to register custom biome Surface decorators + */ + public static class Surface extends TerraEvent { + + public Surface(SurfaceManager manager) { + super(manager); + } + } + + /** + * Register additional layer blocks (such as Snow Layers) + */ + public static class Layers extends TerraEvent { + + public Layers(LayerManager manager) { + super(manager); + } + } + + /** + * Register custom Strata and Geologies + */ + public static class Geology extends TerraEvent { + + public Geology(GeologyManager manager) { + super(manager); + } + } + + /** + * Register custom FeatureModifiers + */ + public static class Features extends TerraEvent { + + public Features(FeatureModifiers manager) { + super(manager); + } + } + + /** + * Register custom Terrain Populators + */ + public static class Terrain extends TerraEvent { + + public Terrain(TerrainProvider provider) { + super(provider); + } + } + + /** + * Register custom ColumnDecorators + * - base decorators process chunk columns early in the generation process (before biome surfaces etc) + * - feature decorators process chunk columns late in the generation process (after all features have been placed) + */ + public static class Decorators extends TerraEvent { + + public Decorators(DecoratorManager manager) { + super(manager); + } + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/MaterialTags.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/MaterialTags.java new file mode 100644 index 0000000..1081916 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/MaterialTags.java @@ -0,0 +1,49 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material; + +import net.minecraft.block.Block; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.Tag; +import net.minecraft.util.ResourceLocation; + +public class MaterialTags { + + public static final Tag WG_ROCK = tag("rock"); + public static final Tag WG_EARTH = tag("earth"); + public static final Tag WG_CLAY = tag("clay"); + public static final Tag WG_SEDIMENT = tag("sediment"); + public static final Tag WG_ORE = tag("ore"); + public static final Tag WG_ERODIBLE = tag("erodible"); + + public static void init() { + + } + + private static Tag tag(String name) { + return new BlockTags.Wrapper(new ResourceLocation("terraforged", name)); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/GeologyManager.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/GeologyManager.java new file mode 100644 index 0000000..dd46b94 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/GeologyManager.java @@ -0,0 +1,58 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.geology; + +import com.terraforged.core.world.geology.Geology; +import com.terraforged.core.world.geology.Strata; +import net.minecraft.block.BlockState; +import net.minecraft.world.biome.Biome; + +public interface GeologyManager { + + StrataGenerator getStrataGenerator(); + + /** + * Register a global strata group (applies to any biome that does not have specific geology defined. + */ + void register(Strata strata); + + /** + * Register a biome specific strata group. + */ + default void register(Biome biome, Strata strata) { + register(biome, strata, false); + } + + /** + * Register a biome specific strata group. + */ + void register(Biome biome, Strata strata, boolean inheritGlobal); + + /** + * Register/replace a biome-specific geology group + */ + void register(Biome biome, Geology geology); +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataConfig.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataConfig.java new file mode 100644 index 0000000..58ee8b2 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataConfig.java @@ -0,0 +1,64 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.geology; + +import me.dags.noise.util.NoiseUtil; + +public class StrataConfig { + + public Config soil = new Config(0, 1, 0.1F, 0.25F); + public Config sediment = new Config(0, 2, 0.05F, 0.15F); + public Config clay = new Config(0, 2, 0.05F, 0.1F); + public Config rock = new Config(10, 30, 0.1F, 1.5F); + + public static class Config { + + public int minLayers; + public int maxLayers; + public float minDepth; + public float maxDepth; + + public Config() { + } + + public Config(int minLayers, int maxLayers, float minDepth, float maxDepth) { + this.minLayers = minLayers; + this.maxLayers = maxLayers; + this.minDepth = minDepth; + this.maxDepth = maxDepth; + } + + public int getLayers(float value) { + int range = maxLayers - minLayers; + return minLayers + NoiseUtil.round(value * range); + } + + public float getDepth(float value) { + float range = maxDepth - minDepth; + return minDepth + value * range; + } + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java new file mode 100644 index 0000000..ae712f4 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/geology/StrataGenerator.java @@ -0,0 +1,34 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.geology; + +import com.terraforged.core.world.geology.Strata; +import net.minecraft.block.BlockState; + +public interface StrataGenerator { + + Strata generate(int seed, int scale, StrataConfig config); +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerManager.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerManager.java new file mode 100644 index 0000000..954687b --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerManager.java @@ -0,0 +1,53 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.layer; + +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; + +import java.util.HashMap; +import java.util.Map; + +public class LayerManager { + + private final Map layers = new HashMap<>(); + + public LayerManager() { + register(LayerMaterial.of(Blocks.SNOW_BLOCK, Blocks.SNOW)); + } + + public void register(LayerMaterial material) { + register(material.getLayerType(), material); + } + + public void register(Block block, LayerMaterial material) { + layers.put(block, material); + } + + public LayerMaterial getMaterial(Block block) { + return layers.get(block); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java new file mode 100644 index 0000000..70a7fee --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java @@ -0,0 +1,135 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.layer; + +import me.dags.noise.util.NoiseUtil; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.state.IProperty; +import net.minecraft.state.properties.BlockStateProperties; + +public class LayerMaterial { + + private static final BlockState AIR = Blocks.AIR.getDefaultState(); + + private final int min; + private final int max; + private final BlockState fullState; + private final BlockState layerState; + private final IProperty layerProperty; + + private LayerMaterial(BlockState fullState, BlockState layerState, IProperty layerProperty) { + this.layerProperty = layerProperty; + this.min = min(layerProperty); + this.max = max(layerProperty); + this.layerState = layerState; + this.fullState = fullState; + } + + public Block getLayerType() { + return layerState.getBlock(); + } + + public BlockState getFull() { + return fullState; + } + + public BlockState getState(float value) { + return getState(getLevel(value)); + } + + public BlockState getState(int level) { + if (level < min) { + return LayerMaterial.AIR; + } + if (level >= max) { + return fullState; + } + return layerState.with(layerProperty, level); + } + + public int getMin() { + return min; + } + + public int getMax() { + return max; + } + + public int getLevel(float depth) { + if (depth > 1) { + depth = getDepth(depth); + } else if (depth < 0) { + depth = 0; + } + return NoiseUtil.round(depth * max); + } + + public float getDepth(float height) { + return height - (int) height; + } + + private static int min(IProperty property) { + return property.getAllowedValues().stream().min(Integer::compareTo).orElse(0); + } + + private static int max(IProperty property) { + return property.getAllowedValues().stream().max(Integer::compareTo).orElse(0); + } + + public static LayerMaterial of(Block block) { + return of(block, BlockStateProperties.LAYERS_1_8); + } + + public static LayerMaterial of(Block block, IProperty property) { + return of(block.getDefaultState(), block.getDefaultState(), property); + } + + public static LayerMaterial of(Block full, Block layer) { + return of(full.getDefaultState(), layer.getDefaultState()); + } + + public static LayerMaterial of(Block full, Block layer, IProperty property) { + return of(full.getDefaultState(), layer.getDefaultState(), property); + } + + public static LayerMaterial of(BlockState layer) { + return of(layer, BlockStateProperties.LAYERS_1_8); + } + + public static LayerMaterial of(BlockState layer, IProperty property) { + return of(layer.with(property, max(property)), layer); + } + + public static LayerMaterial of(BlockState full, BlockState layer) { + return of(full, layer, BlockStateProperties.LAYERS_1_8); + } + + public static LayerMaterial of(BlockState full, BlockState layer, IProperty property) { + return new LayerMaterial(full, layer, property); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/CachedState.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/CachedState.java new file mode 100644 index 0000000..f970121 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/CachedState.java @@ -0,0 +1,65 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.state; + +import net.minecraft.block.BlockState; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +public class CachedState extends StateSupplier { + + private static final List all = new ArrayList<>(); + + private final Supplier supplier; + + private volatile BlockState reference = null; + + public CachedState(Supplier supplier) { + this.supplier = supplier; + all.add(this); + } + + @Override + public BlockState get() { + BlockState state = reference; + if (state == null) { + state = supplier.get(); + reference = state; + } + return state; + } + + public CachedState clear() { + reference = null; + return this; + } + + public static void clearAll() { + all.forEach(CachedState::clear); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/DefaultState.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/DefaultState.java new file mode 100644 index 0000000..63fb3db --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/DefaultState.java @@ -0,0 +1,62 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.state; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistries; + +public class DefaultState extends StateSupplier { + + private final ResourceLocation name; + + private DefaultState(ResourceLocation name) { + this.name = name; + } + + public CachedState cache() { + return new CachedState(this); + } + + @Override + public BlockState get() { + Block block = ForgeRegistries.BLOCKS.getValue(name); + if (block == null) { + block = Blocks.AIR; + } + return block.getDefaultState(); + } + + public static DefaultState of(String name) { + return of(new ResourceLocation(name)); + } + + public static DefaultState of(ResourceLocation name) { + return new DefaultState(name); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateSupplier.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateSupplier.java new file mode 100644 index 0000000..8277b9c --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/StateSupplier.java @@ -0,0 +1,42 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.state; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; + +import java.util.function.Supplier; + +public abstract class StateSupplier implements Supplier { + + public Block getBlock() { + return get().getBlock(); + } + + public BlockState getDefaultState() { + return getBlock().getDefaultState(); + } +} diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/States.java b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/States.java new file mode 100644 index 0000000..3a20632 --- /dev/null +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/material/state/States.java @@ -0,0 +1,44 @@ +/* + * + * MIT License + * + * Copyright (c) 2020 TerraForged + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.terraforged.api.material.state; + +public class States { + + public static final StateSupplier BEDROCK = DefaultState.of("minecraft:bedrock").cache(); + public static final StateSupplier COARSE_DIRT = DefaultState.of("minecraft:coarse_dirt").cache(); + public static final StateSupplier DIRT = DefaultState.of("minecraft:dirt").cache(); + public static final StateSupplier GRASS_BLOCK = DefaultState.of("minecraft:grass_block").cache(); + public static final StateSupplier CLAY = DefaultState.of("minecraft:clay").cache(); + public static final StateSupplier GRAVEL = DefaultState.of("minecraft:gravel").cache(); + public static final StateSupplier LAVA = DefaultState.of("minecraft:lava").cache(); + public static final StateSupplier PACKED_ICE = DefaultState.of("minecraft:packed_ice").cache(); + public static final StateSupplier RED_SANDSTONE = DefaultState.of("minecraft:red_sandstone").cache(); + public static final StateSupplier SAND = DefaultState.of("minecraft:sand").cache(); + public static final StateSupplier SANDSTONE = DefaultState.of("minecraft:sandstone").cache(); + public static final StateSupplier SNOW_BLOCK = DefaultState.of("minecraft:snow_block").cache(); + public static final StateSupplier STONE = DefaultState.of("minecraft:stone").cache(); + public static final StateSupplier WATER = DefaultState.of("minecraft:water").cache(); +} diff --git a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/Renderer.java b/TerraForgedApp/src/main/java/com/terraforged/app/renderer/Renderer.java index efb46c3..fc79524 100644 --- a/TerraForgedApp/src/main/java/com/terraforged/app/renderer/Renderer.java +++ b/TerraForgedApp/src/main/java/com/terraforged/app/renderer/Renderer.java @@ -68,6 +68,9 @@ public abstract class Renderer { return height * el; } else if (applet.controller.getColorMode() == Applet.BIOME_TYPE) { Color c = cell.biomeType.getColor(); + if (cell.riverMask < 0.2) { + c = Color.white; + } float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); float bri = 90 + cell.biomeTypeMask * 10; applet.fill(hsb[0] * 100, hsb[1] * 100, hsb[2] * bri); diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/settings/FilterSettings.java b/TerraForgedCore/src/main/java/com/terraforged/core/settings/FilterSettings.java index dfd935f..85bc81c 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/settings/FilterSettings.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/settings/FilterSettings.java @@ -39,17 +39,17 @@ public class FilterSettings { @Serializable public static class Erosion { - @Range(min = 1000, max = 30000) + @Range(min = 1000, max = 50000) @Comment("Controls the number of erosion iterations") - public int iterations = 15000; + public int iterations = 12000; @Range(min = 0F, max = 1F) @Comment("Controls how quickly material dissolves (during erosion)") - public float erosionRate = 0.35F; + public float erosionRate = 0.4F; @Range(min = 0F, max = 1F) @Comment("Controls how quickly material is deposited (during erosion)") - public float depositeRate = 0.5F; + public float depositeRate = 0.4F; } @Serializable diff --git a/TerraForgedMod b/TerraForgedMod index 51b518e..7b36c66 160000 --- a/TerraForgedMod +++ b/TerraForgedMod @@ -1 +1 @@ -Subproject commit 51b518ee0b8d5bb53357ce9e8259aab41934d331 +Subproject commit 7b36c6610c90356a6c047e789245fd5357fe7d23 diff --git a/settings.gradle b/settings.gradle index 8f3b926..c4f3e68 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,5 +2,6 @@ rootProject.name = "TerraForged" include ":Noise2D" include ":FeatureManager" include ":TerraForgedCore" -include ":TerraForgedApp" -include ":TerraForgedMod" \ No newline at end of file +include ":TerraForgedAPI" +include ":TerraForgedMod" +include ":TerraForgedApp" \ No newline at end of file