add range checks to FastChunk

This commit is contained in:
dags- 2020-03-19 09:04:40 +00:00
parent 9583c1a69f
commit d336a77cef
6 changed files with 29 additions and 109 deletions

View File

@ -62,6 +62,13 @@ public class Levels {
water = NoiseUtil.div(waterY, worldHeight); 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) { public float scale(int level) {
return NoiseUtil.div(level, worldHeight); return NoiseUtil.div(level, worldHeight);
} }

View File

@ -37,22 +37,25 @@ public class FastChunk implements ChunkDelegate {
@Override @Override
public BlockState setBlockState(BlockPos pos, BlockState state, boolean falling) { public BlockState setBlockState(BlockPos pos, BlockState state, boolean falling) {
ChunkSection section = primer.getSection(pos.getY() >> 4); if (pos.getY() >= 0 && pos.getY() < 256) {
section.lock(); ChunkSection section = primer.getSection(pos.getY() >> 4);
int dx = pos.getX() & 15; section.lock();
int dy = pos.getY() & 15; int dx = pos.getX() & 15;
int dz = pos.getZ() & 15; int dy = pos.getY() & 15;
BlockState replaced = section.setBlockState(dx, dy, dz, state, false); int dz = pos.getZ() & 15;
if (state.getBlock() != Blocks.AIR) { BlockState replaced = section.setBlockState(dx, dy, dz, state, false);
mutable.setPos(blockX + dx, pos.getY(), blockZ + dz); if (state.getBlock() != Blocks.AIR) {
if (state.getLightValue(primer, mutable) != 0) { mutable.setPos(blockX + dx, pos.getY(), blockZ + dz);
primer.addLightPosition(mutable); 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); section.unlock();
oceanSurface.update(dx, pos.getY(), dz, state); return replaced;
} }
section.unlock(); return Blocks.AIR.getDefaultState();
return replaced;
} }
public void setBiomes(BiomeContainer biomes) { public void setBiomes(BiomeContainer biomes) {

View File

@ -155,7 +155,7 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator<GenerationSetti
container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> { container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> {
int px = ctx.blockX + dx; int px = ctx.blockX + dx;
int pz = ctx.blockZ + dz; int pz = ctx.blockZ + dz;
int py = (int) (cell.value * getMaxHeight()); int py = ctx.levels.scale(cell.value);
ctx.cell = cell; ctx.cell = cell;
ctx.biome = container.getBiome(dx, dz); ctx.biome = container.getBiome(dx, dz);
ChunkPopulator.INSTANCE.decorate(ctx.chunk, ctx, px, py, pz); ChunkPopulator.INSTANCE.decorate(ctx.chunk, ctx, px, py, pz);
@ -182,7 +182,7 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator<GenerationSetti
getSurfaceManager().getSurface(ctx).buildSurface(px, pz, top, ctx); getSurfaceManager().getSurface(ctx).buildSurface(px, pz, top, ctx);
int py = (int) (cell.value * getMaxHeight()); int py = ctx.levels.scale(cell.value);
for (ColumnDecorator processor : getBaseDecorators()) { for (ColumnDecorator processor : getBaseDecorators()) {
processor.decorate(ctx.buffer, ctx, px, py, pz); processor.decorate(ctx.buffer, ctx, px, py, pz);
} }
@ -238,7 +238,7 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator<GenerationSetti
int chunkZ = Size.blockToChunk(z); int chunkZ = Size.blockToChunk(z);
ChunkReader chunk = getChunkReader(chunkX, chunkZ); ChunkReader chunk = getChunkReader(chunkX, chunkZ);
Cell<?> cell = chunk.getCell(x, z); Cell<?> cell = chunk.getCell(x, z);
return (int) (cell.value * getMaxHeight()); return context.levels.scale(cell.value);
} }
@Override @Override

View File

@ -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);
}
}
}
}

View File

@ -28,12 +28,10 @@ package com.terraforged.mod.decorator.surface;
import com.terraforged.api.chunk.surface.Surface; import com.terraforged.api.chunk.surface.Surface;
import com.terraforged.api.chunk.surface.SurfaceContext; import com.terraforged.api.chunk.surface.SurfaceContext;
import com.terraforged.api.material.state.States; import com.terraforged.api.material.state.States;
import com.terraforged.core.cell.Cell;
import com.terraforged.core.world.heightmap.Levels; import com.terraforged.core.world.heightmap.Levels;
import com.terraforged.mod.chunk.TerraContext; import com.terraforged.mod.chunk.TerraContext;
import me.dags.noise.Module; import me.dags.noise.Module;
import me.dags.noise.Source; import me.dags.noise.Source;
import me.dags.noise.util.NoiseUtil;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder; import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
@ -94,7 +92,7 @@ public class FrozenOcean implements Surface {
} }
// set ocean floor to gravel // 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); int floorDepth = (int) (seaFloor.getValue(x, z) * levels.worldHeight);
for (int dy = 0; dy < floorDepth; dy++) { for (int dy = 0; dy < floorDepth; dy++) {
pos.setY(floorBed - dy); pos.setY(floorBed - dy);
@ -108,8 +106,4 @@ public class FrozenOcean implements Surface {
} }
return States.PACKED_ICE.get(); return States.PACKED_ICE.get();
} }
private static float getMask(Cell<?> cell) {
return NoiseUtil.map(cell.biomeTypeMask * cell.riverMask, 0F, 0.3F, 0.3F);
}
} }

View File

@ -1,4 +1,4 @@
mod_version=0.0.7 mod_version=0.0.8
mc_version=1.15.2 mc_version=1.15.2
forge_version=31.1.1 forge_version=31.1.1
mcp_channel=snapshot mcp_channel=snapshot