From f17036097d3b5c8f7c241cc4df49ed10e06dc45c Mon Sep 17 00:00:00 2001 From: dags- Date: Fri, 28 Feb 2020 21:37:44 +0000 Subject: [PATCH] more pos refactor stuff --- .../api/chunk/column/ColumnDecorator.java | 16 +++++---------- ...ssorContext.java => DecoratorContext.java} | 6 ++++-- .../api/chunk/surface/Surface.java | 20 ++++++++----------- .../api/chunk/surface/SurfaceContext.java | 4 ++-- TerraForgedMod | 2 +- 5 files changed, 20 insertions(+), 28 deletions(-) rename TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/{ProcessorContext.java => DecoratorContext.java} (89%) 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 index f4278a9..e1d0dbf 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ColumnDecorator.java @@ -36,9 +36,9 @@ public interface ColumnDecorator { FastSource variance = (FastSource) Source.perlin(0, 100, 1); - void decorate(IChunk chunk, ProcessorContext context, int x, int y, int z); + void decorate(IChunk chunk, DecoratorContext context, int x, int y, int z); - default void decorate(ChunkSurfaceBuffer buffer, ProcessorContext context, int x, int y, int z) { + default void decorate(ChunkSurfaceBuffer buffer, DecoratorContext context, int x, int y, int z) { decorate(buffer.getDelegate(), context, x, y, z); } @@ -46,11 +46,9 @@ public interface ColumnDecorator { chunk.setBlockState(new BlockPos(x, y, z), state, moving); } - default void fillDown(IChunk chunk, int x, int z, int from, int to, BlockState state) { - try (BlockPos.PooledMutable pos = ColumnDecorator.pos(x, from, z)) { - for (int dy = from; dy > to; dy--) { - chunk.setBlockState(pos.setPos(x, dy, z), state, false); - } + default void fillDown(DecoratorContext context, IChunk chunk, int x, int z, int from, int to, BlockState state) { + for (int dy = from; dy > to; dy--) { + chunk.setBlockState(context.pos.setPos(x, dy, z), state, false); } } @@ -61,8 +59,4 @@ public interface ColumnDecorator { static float getNoise(float x, float z, int seed, int scale, int bias) { return getNoise(x, z, seed, scale / 255F, bias / 255F); } - - static BlockPos.PooledMutable pos(int x, int y, int z) { - return BlockPos.PooledMutable.retain(x, y, z); - } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ProcessorContext.java b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java similarity index 89% rename from TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ProcessorContext.java rename to TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java index 906bff5..c258a67 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/ProcessorContext.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/column/DecoratorContext.java @@ -31,19 +31,21 @@ 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.util.math.BlockPos; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.IChunk; -public class ProcessorContext extends ChunkContext { +public class DecoratorContext extends ChunkContext { public final Levels levels; public final Climate climate; public final Terrains terrains; + public final BlockPos.Mutable pos = new BlockPos.Mutable(); public Biome biome; public Cell cell; - public ProcessorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate) { + public DecoratorContext(IChunk chunk, Levels levels, Terrains terrain, Climate climate) { super(chunk); this.levels = levels; this.climate = climate; 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 index 7eb7567..2fd3ede 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/Surface.java @@ -26,26 +26,22 @@ package com.terraforged.api.chunk.surface; -import com.terraforged.api.chunk.column.ColumnDecorator; 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 { 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) { - try (BlockPos.PooledMutable pos = ColumnDecorator.pos(x, start, z)) { - 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 void fill(int x, int z, int start, int end, SurfaceContext ctx, IChunk chunk, BlockState state) { + if (start < end) { + for (int y = start; y < end; y++) { + chunk.setBlockState(ctx.pos.setPos(x, y, z), state, false); + } + } else if (start > end) { + for (int y = start; y > end; y--) { + chunk.setBlockState(ctx.pos.setPos(x, y, z), state, false); } } } 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 index fd92813..ff6e9cf 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/chunk/surface/SurfaceContext.java @@ -25,7 +25,7 @@ package com.terraforged.api.chunk.surface; -import com.terraforged.api.chunk.column.ProcessorContext; +import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.core.world.climate.Climate; import com.terraforged.core.world.heightmap.Levels; import com.terraforged.core.world.terrain.Terrains; @@ -33,7 +33,7 @@ import net.minecraft.block.BlockState; import net.minecraft.world.chunk.IChunk; import net.minecraft.world.gen.GenerationSettings; -public class SurfaceContext extends ProcessorContext { +public class SurfaceContext extends DecoratorContext { public final BlockState solid; public final BlockState fluid; diff --git a/TerraForgedMod b/TerraForgedMod index 3717ff0..8077a91 160000 --- a/TerraForgedMod +++ b/TerraForgedMod @@ -1 +1 @@ -Subproject commit 3717ff07d10d449d8a5c77ff75cf88f00e277429 +Subproject commit 8077a91476371a9d71567763a55982c5e05b4cdc