From 2606eb1491f4704bbc5ab7ad543b206cb977c9f0 Mon Sep 17 00:00:00 2001 From: dags- Date: Wed, 13 May 2020 20:31:45 +0100 Subject: [PATCH] tidy-up --- .gitignore | 13 +- .../api/material/layer/LayerMaterial.java | 4 +- .../biome/modifier/BiomeModifierManager.java | 6 +- .../mod/biome/modifier/SandBiomeModifier.java | 11 +- .../mod/chunk/TerraChunkGenerator.java | 29 ++-- ...TerraHooks.java => TerraSetupFactory.java} | 31 ++-- .../mod/chunk/fix/ChunkCarverFix.java | 5 +- .../terraforged/mod/chunk/fix/SpawnFix.java | 26 --- .../BiomeGenerator.java | 2 +- .../MobGenerator.java | 20 ++- .../StructureGenerator.java | 3 +- .../TerrainCarver.java | 2 +- .../TerrainGenerator.java | 2 +- .../mod/decorator/feature/LayerDecorator.java | 14 +- .../mod/material/MaterialHelper.java | 151 ------------------ .../terraforged/mod/material/Materials.java | 89 +++++------ .../mod/material/geology/GeoGenerator.java | 14 +- 17 files changed, 114 insertions(+), 308 deletions(-) rename src/main/java/com/terraforged/mod/chunk/{util/TerraHooks.java => TerraSetupFactory.java} (98%) delete mode 100644 src/main/java/com/terraforged/mod/chunk/fix/SpawnFix.java rename src/main/java/com/terraforged/mod/chunk/{component => generator}/BiomeGenerator.java (96%) rename src/main/java/com/terraforged/mod/chunk/{component => generator}/MobGenerator.java (80%) rename src/main/java/com/terraforged/mod/chunk/{component => generator}/StructureGenerator.java (97%) rename src/main/java/com/terraforged/mod/chunk/{component => generator}/TerrainCarver.java (97%) rename src/main/java/com/terraforged/mod/chunk/{component => generator}/TerrainGenerator.java (99%) delete mode 100644 src/main/java/com/terraforged/mod/material/MaterialHelper.java diff --git a/.gitignore b/.gitignore index 0f263bb..f8da0e0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,12 +22,11 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -build/ -out/ -run/ *.iml -.gradle/ + +run/ +out/ +build/ .idea/ -**/build/ -**/out/ -generated/resources/.cache \ No newline at end of file +.gradle/ +.cache/ \ No newline at end of file diff --git a/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java b/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java index 70a7fee..29705cd 100644 --- a/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java +++ b/src/main/java/com/terraforged/api/material/layer/LayerMaterial.java @@ -34,7 +34,7 @@ import net.minecraft.state.properties.BlockStateProperties; public class LayerMaterial { - private static final BlockState AIR = Blocks.AIR.getDefaultState(); + public static final BlockState NONE = Blocks.AIR.getDefaultState(); private final int min; private final int max; @@ -64,7 +64,7 @@ public class LayerMaterial { public BlockState getState(int level) { if (level < min) { - return LayerMaterial.AIR; + return LayerMaterial.NONE; } if (level >= max) { return fullState; diff --git a/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java b/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java index 4b07659..13ed5b7 100644 --- a/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/BiomeModifierManager.java @@ -48,11 +48,7 @@ public class BiomeModifierManager implements BiomeModifier, ModifierManager { List modifiers = new ArrayList<>(); modifiers.add(new BeachModifier(biomes, context)); modifiers.add(new DesertColorModifier(desertBiomes)); - modifiers.add(new SandBiomeModifier( - context.seed, - context.factory.getClimate(), - context.levels - )); + modifiers.add(new SandBiomeModifier(context)); Collections.sort(modifiers); this.biomeModifiers = modifiers; } diff --git a/src/main/java/com/terraforged/mod/biome/modifier/SandBiomeModifier.java b/src/main/java/com/terraforged/mod/biome/modifier/SandBiomeModifier.java index 62cc408..110e1d6 100644 --- a/src/main/java/com/terraforged/mod/biome/modifier/SandBiomeModifier.java +++ b/src/main/java/com/terraforged/mod/biome/modifier/SandBiomeModifier.java @@ -26,10 +26,7 @@ package com.terraforged.mod.biome.modifier; import com.terraforged.core.cell.Cell; -import com.terraforged.core.Seed; -import com.terraforged.world.climate.Climate; -import com.terraforged.world.heightmap.Levels; -import com.terraforged.mod.material.MaterialHelper; +import com.terraforged.mod.chunk.TerraContext; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biomes; import net.minecraftforge.registries.ForgeRegistries; @@ -42,10 +39,10 @@ public class SandBiomeModifier extends AbstractMaxHeightModifier { private final Set biomes; - public SandBiomeModifier(Seed seed, Climate climate, Levels levels) { - super(seed, climate, 50, 2, levels.scale(8), levels.ground(5), levels.ground(25)); + public SandBiomeModifier(TerraContext context) { + super(context.seed, context.factory.getClimate(), 50, 2, context.levels.scale(8), context.levels.ground(5), context.levels.ground(25)); this.biomes = ForgeRegistries.BIOMES.getValues().stream() - .filter(biome -> MaterialHelper.isSand(biome.getSurfaceBuilderConfig().getTop().getBlock())) + .filter(biome -> context.materials.isSand(biome.getSurfaceBuilderConfig().getTop().getBlock())) .collect(Collectors.toSet()); } diff --git a/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java b/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java index 904a1ad..785672f 100644 --- a/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java +++ b/src/main/java/com/terraforged/mod/chunk/TerraChunkGenerator.java @@ -36,12 +36,11 @@ import com.terraforged.mod.feature.manager.FeatureManager; import com.terraforged.mod.feature.manager.data.DataManager; import com.terraforged.mod.Log; import com.terraforged.mod.biome.provider.BiomeProvider; -import com.terraforged.mod.chunk.component.BiomeGenerator; -import com.terraforged.mod.chunk.component.MobGenerator; -import com.terraforged.mod.chunk.component.StructureGenerator; -import com.terraforged.mod.chunk.component.TerrainCarver; -import com.terraforged.mod.chunk.component.TerrainGenerator; -import com.terraforged.mod.chunk.util.TerraHooks; +import com.terraforged.mod.chunk.generator.BiomeGenerator; +import com.terraforged.mod.chunk.generator.MobGenerator; +import com.terraforged.mod.chunk.generator.StructureGenerator; +import com.terraforged.mod.chunk.generator.TerrainCarver; +import com.terraforged.mod.chunk.generator.TerrainGenerator; import com.terraforged.mod.feature.BlockDataManager; import com.terraforged.mod.material.Materials; import com.terraforged.mod.material.geology.GeoManager; @@ -93,16 +92,16 @@ public class TerraChunkGenerator extends ChunkGenerator { this.terrainGenerator = new TerrainGenerator(this); this.structureGenerator = new StructureGenerator(this); - this.surfaceManager = TerraHooks.createSurfaceManager(context); - this.geologyManager = TerraHooks.createGeologyManager(context); - this.baseDecorators = TerraHooks.createBaseDecorators(geologyManager, context); - this.postProcessors = TerraHooks.createFeatureDecorators(context); + this.surfaceManager = TerraSetupFactory.createSurfaceManager(context); + this.geologyManager = TerraSetupFactory.createGeologyManager(context); + this.baseDecorators = TerraSetupFactory.createBaseDecorators(geologyManager, context); + this.postProcessors = TerraSetupFactory.createFeatureDecorators(context); this.regionCache = context.cache; - try (DataManager data = TerraHooks.createDataManager()) { + try (DataManager data = TerraSetupFactory.createDataManager()) { FeatureManager.initData(data); - this.featureManager = TerraHooks.createFeatureManager(data, context); - this.blockDataManager = TerraHooks.createBlockDataManager(data, context); + this.featureManager = TerraSetupFactory.createFeatureManager(data, context); + this.blockDataManager = TerraSetupFactory.createBlockDataManager(data, context); FeatureManager.clearData(); } @@ -161,10 +160,6 @@ public class TerraChunkGenerator extends ChunkGenerator { return mobGenerator.getPossibleCreatures(world, type, pos); } - public final Biome getBiome(BiomeManager biomes, BlockPos pos) { - return super.getBiome(biomes, pos); - } - @Override public final int func_222529_a(int x, int z, Heightmap.Type type) { int chunkX = Size.blockToChunk(x); diff --git a/src/main/java/com/terraforged/mod/chunk/util/TerraHooks.java b/src/main/java/com/terraforged/mod/chunk/TerraSetupFactory.java similarity index 98% rename from src/main/java/com/terraforged/mod/chunk/util/TerraHooks.java rename to src/main/java/com/terraforged/mod/chunk/TerraSetupFactory.java index 5cfce69..a16bc8c 100644 --- a/src/main/java/com/terraforged/mod/chunk/util/TerraHooks.java +++ b/src/main/java/com/terraforged/mod/chunk/TerraSetupFactory.java @@ -1,7 +1,20 @@ -package com.terraforged.mod.chunk.util; +package com.terraforged.mod.chunk; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.surface.SurfaceManager; +import com.terraforged.mod.Log; +import com.terraforged.mod.biome.ModBiomes; +import com.terraforged.mod.biome.surface.IcebergsSurface; +import com.terraforged.mod.biome.surface.SteppeSurface; +import com.terraforged.mod.biome.surface.SwampSurface; +import com.terraforged.mod.decorator.feature.LayerDecorator; +import com.terraforged.mod.decorator.feature.SnowEroder; +import com.terraforged.mod.decorator.terrain.BedrockDecorator; +import com.terraforged.mod.decorator.terrain.CoastDecorator; +import com.terraforged.mod.decorator.terrain.ErosionDecorator; +import com.terraforged.mod.decorator.terrain.GeologyDecorator; +import com.terraforged.mod.feature.BlockDataManager; +import com.terraforged.mod.feature.Matchers; import com.terraforged.mod.feature.manager.FeatureManager; import com.terraforged.mod.feature.manager.data.DataManager; import com.terraforged.mod.feature.manager.matcher.biome.BiomeMatcher; @@ -11,20 +24,6 @@ import com.terraforged.mod.feature.manager.predicate.DeepWater; import com.terraforged.mod.feature.manager.predicate.FeaturePredicate; import com.terraforged.mod.feature.manager.predicate.MinDepth; import com.terraforged.mod.feature.manager.predicate.MinHeight; -import com.terraforged.mod.Log; -import com.terraforged.mod.biome.ModBiomes; -import com.terraforged.mod.biome.surface.IcebergsSurface; -import com.terraforged.mod.biome.surface.SteppeSurface; -import com.terraforged.mod.biome.surface.SwampSurface; -import com.terraforged.mod.chunk.TerraContext; -import com.terraforged.mod.decorator.terrain.BedrockDecorator; -import com.terraforged.mod.decorator.terrain.CoastDecorator; -import com.terraforged.mod.decorator.terrain.ErosionDecorator; -import com.terraforged.mod.decorator.terrain.GeologyDecorator; -import com.terraforged.mod.decorator.feature.LayerDecorator; -import com.terraforged.mod.decorator.feature.SnowEroder; -import com.terraforged.mod.feature.Matchers; -import com.terraforged.mod.feature.BlockDataManager; import com.terraforged.mod.material.geology.GeoManager; import com.terraforged.mod.util.setup.SetupHooks; import net.minecraft.world.biome.Biome; @@ -35,7 +34,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -public class TerraHooks { +public class TerraSetupFactory { public static DataManager createDataManager() { return FeatureManager.data(new File("config/terraforged/datapacks")); diff --git a/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java b/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java index dc12300..0792eae 100644 --- a/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java +++ b/src/main/java/com/terraforged/mod/chunk/fix/ChunkCarverFix.java @@ -27,7 +27,6 @@ package com.terraforged.mod.chunk.fix; import com.terraforged.api.chunk.ChunkDelegate; import com.terraforged.api.material.state.States; -import com.terraforged.mod.material.MaterialHelper; import com.terraforged.mod.material.Materials; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; @@ -51,10 +50,10 @@ public class ChunkCarverFix implements ChunkDelegate { @Override public BlockState getBlockState(BlockPos pos) { BlockState state = getDelegate().getBlockState(pos); - if (MaterialHelper.isAir(state.getBlock())) { + if (materials.isAir(state.getBlock())) { return state; } - if (MaterialHelper.isGrass(state.getBlock())) { + if (materials.isGrass(state.getBlock())) { return States.GRASS_BLOCK.get(); } if (materials.isStone(state.getBlock())) { diff --git a/src/main/java/com/terraforged/mod/chunk/fix/SpawnFix.java b/src/main/java/com/terraforged/mod/chunk/fix/SpawnFix.java deleted file mode 100644 index 19e5459..0000000 --- a/src/main/java/com/terraforged/mod/chunk/fix/SpawnFix.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.terraforged.mod.chunk.fix; - -import net.minecraft.world.GameRules; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -import java.util.concurrent.atomic.AtomicBoolean; - -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) -public class SpawnFix { - - private static final AtomicBoolean MOB_SPAWNING = new AtomicBoolean(); - - @SubscribeEvent - public static void tick(TickEvent.WorldTickEvent event) { - if (event.phase == TickEvent.Phase.START && event.side.isServer()) { - boolean mobSpawning = event.world.getGameRules().get(GameRules.DO_MOB_SPAWNING).get(); - MOB_SPAWNING.set(mobSpawning); - } - } - - public static boolean canSpawnMobs() { - return MOB_SPAWNING.get(); - } -} diff --git a/src/main/java/com/terraforged/mod/chunk/component/BiomeGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/BiomeGenerator.java similarity index 96% rename from src/main/java/com/terraforged/mod/chunk/component/BiomeGenerator.java rename to src/main/java/com/terraforged/mod/chunk/generator/BiomeGenerator.java index 6ba46d4..d9608e1 100644 --- a/src/main/java/com/terraforged/mod/chunk/component/BiomeGenerator.java +++ b/src/main/java/com/terraforged/mod/chunk/generator/BiomeGenerator.java @@ -1,4 +1,4 @@ -package com.terraforged.mod.chunk.component; +package com.terraforged.mod.chunk.generator; import com.terraforged.core.region.chunk.ChunkReader; import com.terraforged.world.terrain.decorator.Decorator; diff --git a/src/main/java/com/terraforged/mod/chunk/component/MobGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/MobGenerator.java similarity index 80% rename from src/main/java/com/terraforged/mod/chunk/component/MobGenerator.java rename to src/main/java/com/terraforged/mod/chunk/generator/MobGenerator.java index 7807102..149b279 100644 --- a/src/main/java/com/terraforged/mod/chunk/component/MobGenerator.java +++ b/src/main/java/com/terraforged/mod/chunk/generator/MobGenerator.java @@ -1,10 +1,10 @@ -package com.terraforged.mod.chunk.component; +package com.terraforged.mod.chunk.generator; import com.terraforged.mod.chunk.TerraChunkGenerator; -import com.terraforged.mod.chunk.fix.SpawnFix; import net.minecraft.entity.EntityClassification; import net.minecraft.util.SharedSeedRandom; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.GameRules; import net.minecraft.world.IWorld; import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.WorldGenRegion; @@ -14,11 +14,18 @@ import net.minecraft.world.spawner.CatSpawner; import net.minecraft.world.spawner.PatrolSpawner; import net.minecraft.world.spawner.PhantomSpawner; import net.minecraft.world.spawner.WorldEntitySpawner; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import java.util.List; +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) public class MobGenerator { + // may be accessed cross-thread + private static volatile boolean mobSpawning = true; + private final CatSpawner catSpawner = new CatSpawner(); private final PatrolSpawner patrolSpawner = new PatrolSpawner(); private final PhantomSpawner phantomSpawner = new PhantomSpawner(); @@ -30,7 +37,7 @@ public class MobGenerator { public final void generateMobs(WorldGenRegion region) { // vanilla does NOT check the mobSpawning gamerule before calling this - if (SpawnFix.canSpawnMobs()) { + if (MobGenerator.mobSpawning) { int chunkX = region.getMainChunkX(); int chunkZ = region.getMainChunkZ(); Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0); @@ -66,4 +73,11 @@ public class MobGenerator { } return world.getBiome(pos).getSpawns(type); } + + @SubscribeEvent + public static void tick(TickEvent.WorldTickEvent event) { + if (event.phase == TickEvent.Phase.START && event.side.isServer()) { + mobSpawning = event.world.getGameRules().get(GameRules.DO_MOB_SPAWNING).get(); + } + } } diff --git a/src/main/java/com/terraforged/mod/chunk/component/StructureGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/StructureGenerator.java similarity index 97% rename from src/main/java/com/terraforged/mod/chunk/component/StructureGenerator.java rename to src/main/java/com/terraforged/mod/chunk/generator/StructureGenerator.java index 948f27b..5965fda 100644 --- a/src/main/java/com/terraforged/mod/chunk/component/StructureGenerator.java +++ b/src/main/java/com/terraforged/mod/chunk/generator/StructureGenerator.java @@ -1,4 +1,4 @@ -package com.terraforged.mod.chunk.component; +package com.terraforged.mod.chunk.generator; import com.terraforged.mod.chunk.TerraChunkGenerator; import net.minecraft.network.DebugPacketSender; @@ -9,7 +9,6 @@ import net.minecraft.util.math.MutableBoundingBox; import net.minecraft.world.IWorld; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.BiomeManager; -import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunk; import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.feature.Feature; diff --git a/src/main/java/com/terraforged/mod/chunk/component/TerrainCarver.java b/src/main/java/com/terraforged/mod/chunk/generator/TerrainCarver.java similarity index 97% rename from src/main/java/com/terraforged/mod/chunk/component/TerrainCarver.java rename to src/main/java/com/terraforged/mod/chunk/generator/TerrainCarver.java index cfbc9cd..5ae3cf2 100644 --- a/src/main/java/com/terraforged/mod/chunk/component/TerrainCarver.java +++ b/src/main/java/com/terraforged/mod/chunk/generator/TerrainCarver.java @@ -1,4 +1,4 @@ -package com.terraforged.mod.chunk.component; +package com.terraforged.mod.chunk.generator; import com.terraforged.mod.chunk.TerraChunkGenerator; import com.terraforged.mod.chunk.fix.ChunkCarverFix; diff --git a/src/main/java/com/terraforged/mod/chunk/component/TerrainGenerator.java b/src/main/java/com/terraforged/mod/chunk/generator/TerrainGenerator.java similarity index 99% rename from src/main/java/com/terraforged/mod/chunk/component/TerrainGenerator.java rename to src/main/java/com/terraforged/mod/chunk/generator/TerrainGenerator.java index 0bbd3d6..185f5f0 100644 --- a/src/main/java/com/terraforged/mod/chunk/component/TerrainGenerator.java +++ b/src/main/java/com/terraforged/mod/chunk/generator/TerrainGenerator.java @@ -1,4 +1,4 @@ -package com.terraforged.mod.chunk.component; +package com.terraforged.mod.chunk.generator; import com.terraforged.api.chunk.column.ColumnDecorator; import com.terraforged.api.chunk.column.DecoratorContext; diff --git a/src/main/java/com/terraforged/mod/decorator/feature/LayerDecorator.java b/src/main/java/com/terraforged/mod/decorator/feature/LayerDecorator.java index cb26630..41a3d5a 100644 --- a/src/main/java/com/terraforged/mod/decorator/feature/LayerDecorator.java +++ b/src/main/java/com/terraforged/mod/decorator/feature/LayerDecorator.java @@ -31,7 +31,6 @@ import com.terraforged.api.material.layer.LayerManager; import com.terraforged.api.material.layer.LayerMaterial; import com.terraforged.core.cell.Cell; import com.terraforged.world.heightmap.Levels; -import com.terraforged.mod.material.MaterialHelper; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.IChunk; @@ -50,13 +49,13 @@ public class LayerDecorator implements ColumnDecorator { // if block is already a layer-type then simply set the layer property BlockState state = chunk.getBlockState(context.pos); - LayerMaterial material = layerManager.getMaterial(state.getBlock()); - if (material != null) { - setLayer(chunk, context.pos, material, context.cell, context.levels, 0F); + if (state.isAir(chunk, context.pos)) { return; } - if (MaterialHelper.isAir(state.getBlock())) { + LayerMaterial material = layerManager.getMaterial(state.getBlock()); + if (material != null) { + setLayer(chunk, context.pos, material, context.cell, context.levels, 0F); return; } @@ -65,7 +64,8 @@ public class LayerDecorator implements ColumnDecorator { // block below is solid if (chunk.getBlockState(context.pos.setPos(x, y, z)).getMaterial().blocksMovement()) { // block above is air - if (MaterialHelper.isAir(chunk.getBlockState(context.pos.setPos(x, y + 2, z)).getBlock())) { + BlockState above = chunk.getBlockState(context.pos.setPos(x, y + 2, z)); + if (above.isAir(chunk, context.pos)) { // setLayer(chunk, pos.setPos(x, y + 1, z), context.cell, context.levels, 0.25F); } } @@ -78,7 +78,7 @@ public class LayerDecorator implements ColumnDecorator { if (depth > min) { int level = material.getLevel(depth); BlockState layer = material.getState(level); - if (MaterialHelper.isAir(layer.getBlock())) { + if (layer == LayerMaterial.NONE) { return; } chunk.setBlockState(pos, layer, false); diff --git a/src/main/java/com/terraforged/mod/material/MaterialHelper.java b/src/main/java/com/terraforged/mod/material/MaterialHelper.java deleted file mode 100644 index a6e68c6..0000000 --- a/src/main/java/com/terraforged/mod/material/MaterialHelper.java +++ /dev/null @@ -1,151 +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.material; - -import com.google.common.collect.Sets; -import com.terraforged.core.concurrent.ObjectPool; -import com.terraforged.mod.util.DummyBlockReader; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.ConcretePowderBlock; -import net.minecraft.block.material.Material; -import net.minecraft.tags.BlockTags; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.gen.feature.ConfiguredFeature; -import net.minecraft.world.gen.feature.DecoratedFeatureConfig; -import net.minecraft.world.gen.feature.OreFeatureConfig; -import net.minecraftforge.common.Tags; -import net.minecraftforge.registries.IForgeRegistryEntry; - -import java.util.Set; - -public class MaterialHelper { - - private static final Set BLACKLIST = Sets.newHashSet( - Blocks.INFESTED_CHISELED_STONE_BRICKS, - Blocks.INFESTED_COBBLESTONE, - Blocks.INFESTED_CRACKED_STONE_BRICKS, - Blocks.INFESTED_MOSSY_STONE_BRICKS, - Blocks.INFESTED_STONE, - Blocks.INFESTED_STONE_BRICKS, - Blocks.SLIME_BLOCK, - Blocks.RED_SAND, - Blocks.SOUL_SAND, - // honey etc - Blocks.HONEY_BLOCK, - Blocks.HONEYCOMB_BLOCK, - Blocks.BEE_NEST, - Blocks.BEEHIVE, - Blocks.COMPOSTER - ); - - public static boolean isAir(Block block) { - return block == Blocks.AIR || block == Blocks.CAVE_AIR || block == Blocks.VOID_AIR; - } - - public static boolean isGrass(Block block) { - return block == Blocks.GRASS_BLOCK || block == Blocks.MYCELIUM; - } - - public static boolean isStone(Block block) { - return Tags.Blocks.STONE.contains(block) - && !isBlacklisted(block) - && !("" + block.getRegistryName()).contains("polished_"); - } - - public static boolean isDirt(Block block) { - return Tags.Blocks.DIRT.contains(block) - && !isBlacklisted(block); - } - - public static boolean isClay(Block block) { - return block.getDefaultState().getMaterial() == Material.CLAY - && !isBlacklisted(block); - } - - public static boolean isSand(Block block) { - return BlockTags.SAND.contains(block) - && !isBlacklisted(block) - && !(block instanceof ConcretePowderBlock); - } - - public static boolean isSediment(Block block) { - return (isSand(block) || isGravel(block)) - && !isBlacklisted(block) - && !(block instanceof ConcretePowderBlock); - } - - public static boolean isGravel(Block block) { - return getName(block).contains("gravel"); - } - - public static boolean isOre(Block block) { - return Tags.Blocks.ORES.contains(block) - && !isBlacklisted(block); - } - - public static boolean isBlacklisted(Block block) { - return BLACKLIST.contains(block); - } - - public static String getName(IForgeRegistryEntry entry) { - return "" + entry.getRegistryName(); - } - - public static String getNamespace(IForgeRegistryEntry entry) { - ResourceLocation name = entry.getRegistryName(); - if (name == null) { - return "unknown"; - } - return name.getNamespace(); - } - - public static float getHardness(BlockState state) { - try (ObjectPool.Item reader = DummyBlockReader.pooled()) { - reader.getValue().set(state); - return state.getBlockHardness(reader.getValue(), BlockPos.ZERO); - } - } - - public static boolean isCube(BlockState state) { - try (ObjectPool.Item reader = DummyBlockReader.pooled()) { - reader.getValue().set(state); - return state.isNormalCube(reader.getValue(), BlockPos.ZERO); - } - } - - public static OreFeatureConfig getOreConfig(ConfiguredFeature feature) { - if (feature.config instanceof DecoratedFeatureConfig) { - DecoratedFeatureConfig config = (DecoratedFeatureConfig) feature.config; - if (config.feature.config instanceof OreFeatureConfig) { - return (OreFeatureConfig) config.feature.config; - } - } - return null; - } -} diff --git a/src/main/java/com/terraforged/mod/material/Materials.java b/src/main/java/com/terraforged/mod/material/Materials.java index 151450d..c4b8d70 100644 --- a/src/main/java/com/terraforged/mod/material/Materials.java +++ b/src/main/java/com/terraforged/mod/material/Materials.java @@ -27,52 +27,31 @@ package com.terraforged.mod.material; import com.terraforged.api.material.WGTags; import com.terraforged.api.material.layer.LayerManager; +import com.terraforged.api.material.state.States; +import com.terraforged.core.concurrent.ObjectPool; +import com.terraforged.mod.util.DummyBlockReader; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import it.unimi.dsi.fastutil.objects.ObjectSets; +import net.minecraft.block.AirBlock; import net.minecraft.block.Block; -import net.minecraft.block.Blocks; +import net.minecraft.block.BlockState; +import net.minecraft.block.ConcretePowderBlock; +import net.minecraft.block.GrassBlock; +import net.minecraft.block.MyceliumBlock; +import net.minecraft.tags.BlockTags; import net.minecraft.tags.Tag; -import net.minecraftforge.registries.ForgeRegistries; +import net.minecraft.util.math.BlockPos; -import java.util.Collection; -import java.util.HashSet; import java.util.Set; -import java.util.function.Predicate; -@Deprecated public class Materials { - private final Set stone = create(WGTags.STONE); - private final Set dirt = create(WGTags.DIRT); - private final Set clay = create(WGTags.CLAY); - private final Set sediment = create(WGTags.SEDIMENT); - private final Set erodible = create(WGTags.ERODIBLE); - private final LayerManager layerManager = new LayerManager(); - - public Materials() { - Predicate filter = getTagFilter(); - for (Block block : ForgeRegistries.BLOCKS) { - if (filter.test(block)) { - continue; - } - - if (!MaterialHelper.isCube(block.getDefaultState())) { - continue; - } - - if (MaterialHelper.isStone(block)) { - stone.add(block); - } else if (MaterialHelper.isDirt(block)) { - dirt.add(block); - } else if (MaterialHelper.isClay(block)) { - clay.add(block); - } else if (MaterialHelper.isSediment(block)) { - sediment.add(block); - } - } - - if (stone.isEmpty()) { - stone.add(Blocks.STONE); - } - } + public final LayerManager layerManager = new LayerManager(); + public final Set stone = create(WGTags.STONE, States.STONE.getBlock()); + public final Set dirt = create(WGTags.DIRT, States.DIRT.getBlock()); + public final Set clay = create(WGTags.CLAY, States.CLAY.getBlock()); + public final Set sediment = create(WGTags.SEDIMENT, States.GRAVEL.getBlock()); + public final Set erodible = create(WGTags.ERODIBLE, null); public LayerManager getLayerManager() { return layerManager; @@ -98,22 +77,30 @@ public class Materials { return erodible.contains(block); } - private static Set create(Tag tag) { - return new HashSet<>(tag.getAllElements()); + public boolean isAir(Block block) { + return block instanceof AirBlock; } - private static Predicate getTagFilter() { - Set namespaces = new HashSet<>(); - collectNamespace(namespaces, WGTags.STONE.getAllElements()); - collectNamespace(namespaces, WGTags.DIRT.getAllElements()); - collectNamespace(namespaces, WGTags.DIRT.getAllElements()); - collectNamespace(namespaces, WGTags.SEDIMENT.getAllElements()); - return b -> namespaces.contains(MaterialHelper.getNamespace(b)); + public boolean isGrass(Block block) { + return block instanceof GrassBlock || block instanceof MyceliumBlock; } - private static void collectNamespace(Set set, Collection blocks) { - for (Block block : blocks) { - set.add(MaterialHelper.getNamespace(block)); + public boolean isSand(Block block) { + return BlockTags.SAND.contains(block) && !(block instanceof ConcretePowderBlock); + } + + private static Set create(Tag tag, Block def) { + ObjectOpenHashSet set = new ObjectOpenHashSet<>(tag.getAllElements()); + if (set.isEmpty() && def != null) { + set.add(def); + } + return ObjectSets.unmodifiable(set); + } + + public static float getHardness(BlockState state) { + try (ObjectPool.Item reader = DummyBlockReader.pooled()) { + reader.getValue().set(state); + return state.getBlockHardness(reader.getValue(), BlockPos.ZERO); } } } diff --git a/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java b/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java index 0c6ff2d..947d6cd 100644 --- a/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java +++ b/src/main/java/com/terraforged/mod/material/geology/GeoGenerator.java @@ -25,12 +25,10 @@ package com.terraforged.mod.material.geology; -import com.terraforged.api.material.WGTags; import com.terraforged.api.material.geology.StrataConfig; import com.terraforged.api.material.geology.StrataGenerator; -import com.terraforged.world.geology.Strata; -import com.terraforged.mod.material.MaterialHelper; import com.terraforged.mod.material.Materials; +import com.terraforged.world.geology.Strata; import me.dags.noise.Source; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -50,10 +48,10 @@ public class GeoGenerator implements StrataGenerator { public GeoGenerator(Materials materials) { types.add(Source.PERLIN); - rock = new ArrayList<>(WGTags.STONE.getAllElements()); - soil = new ArrayList<>(WGTags.DIRT.getAllElements()); - clay = new ArrayList<>(WGTags.CLAY.getAllElements()); - sediment = new ArrayList<>(WGTags.SEDIMENT.getAllElements()); + rock = new ArrayList<>(materials.stone); + soil = new ArrayList<>(materials.dirt); + clay = new ArrayList<>(materials.clay); + sediment = new ArrayList<>(materials.sediment); } @Override @@ -100,7 +98,7 @@ public class GeoGenerator implements StrataGenerator { } private List sortHardness(List layers) { - layers.sort(Comparator.comparing(s -> MaterialHelper.getHardness(s.state))); + layers.sort(Comparator.comparing(s -> Materials.getHardness(s.state))); return layers; }