diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Levels.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Levels.java index 144f8b0..bc1f6a6 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Levels.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/heightmap/Levels.java @@ -62,6 +62,13 @@ public class Levels { water = NoiseUtil.div(waterY, worldHeight); } + public int scale(float value) { + if (value >= 1F) { + return worldHeight - 1; + } + return (int) (value * worldHeight); + } + public float scale(int level) { return NoiseUtil.div(level, worldHeight); } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/FastChunk.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/FastChunk.java index 7a51b98..e242c11 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/FastChunk.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/FastChunk.java @@ -37,22 +37,25 @@ public class FastChunk implements ChunkDelegate { @Override public BlockState setBlockState(BlockPos pos, BlockState state, boolean falling) { - ChunkSection section = primer.getSection(pos.getY() >> 4); - section.lock(); - int dx = pos.getX() & 15; - int dy = pos.getY() & 15; - int dz = pos.getZ() & 15; - BlockState replaced = section.setBlockState(dx, dy, dz, state, false); - if (state.getBlock() != Blocks.AIR) { - mutable.setPos(blockX + dx, pos.getY(), blockZ + dz); - if (state.getLightValue(primer, mutable) != 0) { - primer.addLightPosition(mutable); + if (pos.getY() >= 0 && pos.getY() < 256) { + ChunkSection section = primer.getSection(pos.getY() >> 4); + section.lock(); + int dx = pos.getX() & 15; + int dy = pos.getY() & 15; + int dz = pos.getZ() & 15; + BlockState replaced = section.setBlockState(dx, dy, dz, state, false); + if (state.getBlock() != Blocks.AIR) { + mutable.setPos(blockX + dx, pos.getY(), blockZ + dz); + if (state.getLightValue(primer, mutable) != 0) { + primer.addLightPosition(mutable); + } + worldSurface.update(dx, pos.getY(), dz, state); + oceanSurface.update(dx, pos.getY(), dz, state); } - worldSurface.update(dx, pos.getY(), dz, state); - oceanSurface.update(dx, pos.getY(), dz, state); + section.unlock(); + return replaced; } - section.unlock(); - return replaced; + return Blocks.AIR.getDefaultState(); } public void setBiomes(BiomeContainer biomes) { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java index 3da3775..c1413b6 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java @@ -155,7 +155,7 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator { int px = ctx.blockX + dx; int pz = ctx.blockZ + dz; - int py = (int) (cell.value * getMaxHeight()); + int py = ctx.levels.scale(cell.value); ctx.cell = cell; ctx.biome = container.getBiome(dx, dz); ChunkPopulator.INSTANCE.decorate(ctx.chunk, ctx, px, py, pz); @@ -182,7 +182,7 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator cell = chunk.getCell(x, z); - return (int) (cell.value * getMaxHeight()); + return context.levels.scale(cell.value); } @Override diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/RiverDecorator.java b/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/RiverDecorator.java deleted file mode 100644 index 62b5946..0000000 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/base/RiverDecorator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * 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.mod.decorator.base; - -import com.terraforged.api.chunk.column.ColumnDecorator; -import com.terraforged.api.chunk.column.DecoratorContext; -import com.terraforged.api.material.state.States; -import com.terraforged.core.util.Seed; -import com.terraforged.core.world.heightmap.Levels; -import com.terraforged.core.world.terrain.Terrain; -import com.terraforged.mod.chunk.TerraContext; -import me.dags.noise.Module; -import me.dags.noise.Source; -import net.minecraft.block.BlockState; -import net.minecraft.world.chunk.IChunk; - -public class RiverDecorator implements ColumnDecorator { - - private final Levels levels; - private final Terrain river; - private final Terrain riverBank; - - private final BlockState dirt; - private final BlockState sand; - private final BlockState gravel; - - private final Module noise1; - - public RiverDecorator(TerraContext context) { - Seed seed = context.seed.nextSeed(); - this.levels = context.levels; - this.river = context.terrain.river; - this.riverBank = context.terrain.riverBanks; - this.dirt = States.DIRT.get(); - this.sand = States.SAND.get(); - this.gravel = States.GRAVEL.get(); - this.noise1 = Source.perlin(seed.next(), 50, 1); - } - - @Override - public void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z) { - if (context.cell.tag == river) { - chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false); - return; - } - if (context.cell.tag == riverBank) { - float value = noise1.getValue(x, z) * 5; - if (y + value >= levels.waterY) { - if (context.cell.steepness > 0.5) { - chunk.setBlockState(context.pos.setPos(x, y, z), gravel, false); - } else if (context.cell.steepness < 0.3) { - chunk.setBlockState(context.pos.setPos(x, y, z), sand, false); - } else { - chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false); - } - } else { - chunk.setBlockState(context.pos.setPos(x, y, z), dirt, false); - } - } - } -} diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/FrozenOcean.java b/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/FrozenOcean.java index f20c5fa..fb33aa1 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/FrozenOcean.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/decorator/surface/FrozenOcean.java @@ -28,12 +28,10 @@ package com.terraforged.mod.decorator.surface; import com.terraforged.api.chunk.surface.Surface; import com.terraforged.api.chunk.surface.SurfaceContext; import com.terraforged.api.material.state.States; -import com.terraforged.core.cell.Cell; import com.terraforged.core.world.heightmap.Levels; import com.terraforged.mod.chunk.TerraContext; import me.dags.noise.Module; import me.dags.noise.Source; -import me.dags.noise.util.NoiseUtil; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; @@ -94,7 +92,7 @@ public class FrozenOcean implements Surface { } // set ocean floor to gravel - int floorBed = (int) (ctx.cell.value * ctx.levels.worldHeight); + int floorBed = ctx.levels.scale(ctx.cell.value); int floorDepth = (int) (seaFloor.getValue(x, z) * levels.worldHeight); for (int dy = 0; dy < floorDepth; dy++) { pos.setY(floorBed - dy); @@ -108,8 +106,4 @@ public class FrozenOcean implements Surface { } return States.PACKED_ICE.get(); } - - private static float getMask(Cell cell) { - return NoiseUtil.map(cell.biomeTypeMask * cell.riverMask, 0F, 0.3F, 0.3F); - } } diff --git a/gradle.properties b/gradle.properties index 8ccf744..8a91541 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -mod_version=0.0.7 +mod_version=0.0.8 mc_version=1.15.2 forge_version=31.1.1 mcp_channel=snapshot