From dfb3a4c7b20eb30d0d5378bdc648fc91ac4e2934 Mon Sep 17 00:00:00 2001 From: dags- Date: Wed, 26 Feb 2020 14:57:37 +0000 Subject: [PATCH] - use maven-publish plugin - provide context with setup events --- ...ierRegistrar.java => ModifierManager.java} | 6 +- .../api/chunk/column/ColumnDecorator.java | 16 +++-- .../api/chunk/surface/Surface.java | 18 +++--- .../{TerraEvent.java => SetupEvent.java} | 64 +++++++++++++------ .../provider/StandardTerrainProvider.java | 6 -- .../terrain/provider/TerrainProvider.java | 3 - TerraForgedMod | 2 +- 7 files changed, 69 insertions(+), 46 deletions(-) rename TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/{BiomeModifierRegistrar.java => ModifierManager.java} (93%) rename TerraForgedAPI/src/main/java/com/terraforged/api/event/{TerraEvent.java => SetupEvent.java} (57%) diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifierRegistrar.java b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/ModifierManager.java similarity index 93% rename from TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifierRegistrar.java rename to TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/ModifierManager.java index 6193137..dc9bc07 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/BiomeModifierRegistrar.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/biome/modifier/ModifierManager.java @@ -1,5 +1,5 @@ /* - * + * * MIT License * * Copyright (c) 2020 TerraForged @@ -25,7 +25,7 @@ package com.terraforged.api.biome.modifier; -public interface BiomeModifierRegistrar { - +public interface ModifierManager { + void register(BiomeModifier modifier); } 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 0a1b24f..5bdc658 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 @@ -35,8 +35,6 @@ 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); @@ -44,9 +42,15 @@ public interface ColumnDecorator { decorate(buffer.getDelegate(), context, x, y, z); } + default void setState(IChunk chunk, int x, int y, int z, BlockState state, boolean moving) { + chunk.setBlockState(new BlockPos(x, y, z), state, moving); + } + 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); + try (BlockPos.PooledMutable pos = pos()) { + for (int dy = from; dy > to; dy--) { + chunk.setBlockState(pos.setPos(x, dy, z), state, false); + } } } @@ -57,4 +61,8 @@ 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() { + return BlockPos.PooledMutable.retain(); + } } 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 50880f8..6945177 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 @@ -33,18 +33,18 @@ 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); + try (BlockPos.PooledMutable pos = BlockPos.PooledMutable.retain()) { + 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); + } } } } diff --git a/TerraForgedAPI/src/main/java/com/terraforged/api/event/TerraEvent.java b/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java similarity index 57% rename from TerraForgedAPI/src/main/java/com/terraforged/api/event/TerraEvent.java rename to TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java index 6e4fbc0..e05a98c 100644 --- a/TerraForgedAPI/src/main/java/com/terraforged/api/event/TerraEvent.java +++ b/TerraForgedAPI/src/main/java/com/terraforged/api/event/SetupEvent.java @@ -25,73 +25,97 @@ package com.terraforged.api.event; +import com.terraforged.api.biome.modifier.ModifierManager; 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.GeneratorContext; 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 { +public abstract class SetupEvent extends Event { private final T manager; + private final GeneratorContext context; - public TerraEvent(T manager) { + public SetupEvent(T manager, GeneratorContext context) { this.manager = manager; + this.context = context; } + /** + * Returns the Manager/Service being setup + */ public T getManager() { return manager; } + /** + * Returns the generator setup context + */ + public GeneratorContext getContext() { + return context; + } + /** * Can be used to register custom biome Surface decorators */ - public static class Surface extends TerraEvent { + public static class Surface extends SetupEvent { - public Surface(SurfaceManager manager) { - super(manager); + public Surface(SurfaceManager manager, GeneratorContext context) { + super(manager, context); } } /** * Register additional layer blocks (such as Snow Layers) */ - public static class Layers extends TerraEvent { + public static class Layers extends SetupEvent { - public Layers(LayerManager manager) { - super(manager); + public Layers(LayerManager manager, GeneratorContext context) { + super(manager, context); } } /** * Register custom Strata and Geologies */ - public static class Geology extends TerraEvent { + public static class Geology extends SetupEvent { - public Geology(GeologyManager manager) { - super(manager); + public Geology(GeologyManager manager, GeneratorContext context) { + super(manager, context); + } + } + + /** + * Register custom BiomeModifiers + */ + public static class BiomeModifier extends SetupEvent { + + public BiomeModifier(ModifierManager manager, GeneratorContext context) { + super(manager, context); } } /** * Register custom FeatureModifiers */ - public static class Features extends TerraEvent { + public static class Features extends SetupEvent { - public Features(FeatureModifiers manager) { - super(manager); + public Features(FeatureModifiers manager, GeneratorContext context) { + super(manager, context); } } /** * Register custom Terrain Populators */ - public static class Terrain extends TerraEvent { + public static class Terrain extends SetupEvent { - public Terrain(TerrainProvider provider) { - super(provider); + public Terrain(TerrainProvider provider, GeneratorContext context) { + super(provider, context); } } @@ -100,10 +124,10 @@ public abstract class TerraEvent extends Event { * - 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 static class Decorators extends SetupEvent { - public Decorators(DecoratorManager manager) { - super(manager); + public Decorators(DecoratorManager manager, GeneratorContext context) { + super(manager, context); } } } diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java index 1f12bc8..48e97f5 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/StandardTerrainProvider.java @@ -32,7 +32,6 @@ import com.terraforged.core.world.heightmap.RegionConfig; import com.terraforged.core.world.terrain.LandForms; import com.terraforged.core.world.terrain.Terrain; import com.terraforged.core.world.terrain.TerrainPopulator; -import com.terraforged.core.world.terrain.Terrains; import com.terraforged.core.world.terrain.VolcanoPopulator; import me.dags.noise.Module; import me.dags.noise.Source; @@ -78,11 +77,6 @@ public class StandardTerrainProvider implements TerrainProvider { registerUnMixable(context.terrain.mountains, landForms.mountains3(context.seed)); } - @Override - public Terrains getTerrain() { - return context.terrain; - } - @Override public void registerMixable(TerrainPopulator populator) { populators.putIfAbsent(populator.getType(), populator); diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProvider.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProvider.java index 6f7668b..58131e6 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProvider.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/terrain/provider/TerrainProvider.java @@ -29,7 +29,6 @@ import com.terraforged.core.cell.Populator; import com.terraforged.core.world.terrain.LandForms; import com.terraforged.core.world.terrain.Terrain; import com.terraforged.core.world.terrain.TerrainPopulator; -import com.terraforged.core.world.terrain.Terrains; import me.dags.noise.Module; import java.util.List; @@ -39,8 +38,6 @@ import java.util.List; */ public interface TerrainProvider { - Terrains getTerrain(); - LandForms getLandforms(); /** diff --git a/TerraForgedMod b/TerraForgedMod index f7e27c7..0cd6356 160000 --- a/TerraForgedMod +++ b/TerraForgedMod @@ -1 +1 @@ -Subproject commit f7e27c70a2a2b30225a85137688d2014f9ad1b6f +Subproject commit 0cd63563bdc0fad258d78c21dfed1b14c975bdfd