add range checks to FastChunk
This commit is contained in:
parent
9583c1a69f
commit
d336a77cef
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -155,7 +155,7 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator<GenerationSetti
|
||||
container.getChunkReader().iterate(context, (cell, dx, dz, ctx) -> {
|
||||
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<GenerationSetti
|
||||
|
||||
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()) {
|
||||
processor.decorate(ctx.buffer, ctx, px, py, pz);
|
||||
}
|
||||
@ -238,7 +238,7 @@ public class TerraChunkGenerator extends ObfHelperChunkGenerator<GenerationSetti
|
||||
int chunkZ = Size.blockToChunk(z);
|
||||
ChunkReader chunk = getChunkReader(chunkX, chunkZ);
|
||||
Cell<?> cell = chunk.getCell(x, z);
|
||||
return (int) (cell.value * getMaxHeight());
|
||||
return context.levels.scale(cell.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user