This commit is contained in:
dags- 2020-05-13 20:31:45 +01:00
parent e732714083
commit 2606eb1491
17 changed files with 114 additions and 308 deletions

13
.gitignore vendored
View File

@ -22,12 +22,11 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
build/
out/
run/
*.iml *.iml
.gradle/
run/
out/
build/
.idea/ .idea/
**/build/ .gradle/
**/out/ .cache/
generated/resources/.cache

View File

@ -34,7 +34,7 @@ import net.minecraft.state.properties.BlockStateProperties;
public class LayerMaterial { 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 min;
private final int max; private final int max;
@ -64,7 +64,7 @@ public class LayerMaterial {
public BlockState getState(int level) { public BlockState getState(int level) {
if (level < min) { if (level < min) {
return LayerMaterial.AIR; return LayerMaterial.NONE;
} }
if (level >= max) { if (level >= max) {
return fullState; return fullState;

View File

@ -48,11 +48,7 @@ public class BiomeModifierManager implements BiomeModifier, ModifierManager {
List<BiomeModifier> modifiers = new ArrayList<>(); List<BiomeModifier> modifiers = new ArrayList<>();
modifiers.add(new BeachModifier(biomes, context)); modifiers.add(new BeachModifier(biomes, context));
modifiers.add(new DesertColorModifier(desertBiomes)); modifiers.add(new DesertColorModifier(desertBiomes));
modifiers.add(new SandBiomeModifier( modifiers.add(new SandBiomeModifier(context));
context.seed,
context.factory.getClimate(),
context.levels
));
Collections.sort(modifiers); Collections.sort(modifiers);
this.biomeModifiers = modifiers; this.biomeModifiers = modifiers;
} }

View File

@ -26,10 +26,7 @@
package com.terraforged.mod.biome.modifier; package com.terraforged.mod.biome.modifier;
import com.terraforged.core.cell.Cell; import com.terraforged.core.cell.Cell;
import com.terraforged.core.Seed; import com.terraforged.mod.chunk.TerraContext;
import com.terraforged.world.climate.Climate;
import com.terraforged.world.heightmap.Levels;
import com.terraforged.mod.material.MaterialHelper;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.Biomes;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
@ -42,10 +39,10 @@ public class SandBiomeModifier extends AbstractMaxHeightModifier {
private final Set<Biome> biomes; private final Set<Biome> biomes;
public SandBiomeModifier(Seed seed, Climate climate, Levels levels) { public SandBiomeModifier(TerraContext context) {
super(seed, climate, 50, 2, levels.scale(8), levels.ground(5), levels.ground(25)); 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() 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()); .collect(Collectors.toSet());
} }

View File

@ -36,12 +36,11 @@ import com.terraforged.mod.feature.manager.FeatureManager;
import com.terraforged.mod.feature.manager.data.DataManager; import com.terraforged.mod.feature.manager.data.DataManager;
import com.terraforged.mod.Log; import com.terraforged.mod.Log;
import com.terraforged.mod.biome.provider.BiomeProvider; import com.terraforged.mod.biome.provider.BiomeProvider;
import com.terraforged.mod.chunk.component.BiomeGenerator; import com.terraforged.mod.chunk.generator.BiomeGenerator;
import com.terraforged.mod.chunk.component.MobGenerator; import com.terraforged.mod.chunk.generator.MobGenerator;
import com.terraforged.mod.chunk.component.StructureGenerator; import com.terraforged.mod.chunk.generator.StructureGenerator;
import com.terraforged.mod.chunk.component.TerrainCarver; import com.terraforged.mod.chunk.generator.TerrainCarver;
import com.terraforged.mod.chunk.component.TerrainGenerator; import com.terraforged.mod.chunk.generator.TerrainGenerator;
import com.terraforged.mod.chunk.util.TerraHooks;
import com.terraforged.mod.feature.BlockDataManager; import com.terraforged.mod.feature.BlockDataManager;
import com.terraforged.mod.material.Materials; import com.terraforged.mod.material.Materials;
import com.terraforged.mod.material.geology.GeoManager; import com.terraforged.mod.material.geology.GeoManager;
@ -93,16 +92,16 @@ public class TerraChunkGenerator extends ChunkGenerator<GenerationSettings> {
this.terrainGenerator = new TerrainGenerator(this); this.terrainGenerator = new TerrainGenerator(this);
this.structureGenerator = new StructureGenerator(this); this.structureGenerator = new StructureGenerator(this);
this.surfaceManager = TerraHooks.createSurfaceManager(context); this.surfaceManager = TerraSetupFactory.createSurfaceManager(context);
this.geologyManager = TerraHooks.createGeologyManager(context); this.geologyManager = TerraSetupFactory.createGeologyManager(context);
this.baseDecorators = TerraHooks.createBaseDecorators(geologyManager, context); this.baseDecorators = TerraSetupFactory.createBaseDecorators(geologyManager, context);
this.postProcessors = TerraHooks.createFeatureDecorators(context); this.postProcessors = TerraSetupFactory.createFeatureDecorators(context);
this.regionCache = context.cache; this.regionCache = context.cache;
try (DataManager data = TerraHooks.createDataManager()) { try (DataManager data = TerraSetupFactory.createDataManager()) {
FeatureManager.initData(data); FeatureManager.initData(data);
this.featureManager = TerraHooks.createFeatureManager(data, context); this.featureManager = TerraSetupFactory.createFeatureManager(data, context);
this.blockDataManager = TerraHooks.createBlockDataManager(data, context); this.blockDataManager = TerraSetupFactory.createBlockDataManager(data, context);
FeatureManager.clearData(); FeatureManager.clearData();
} }
@ -161,10 +160,6 @@ public class TerraChunkGenerator extends ChunkGenerator<GenerationSettings> {
return mobGenerator.getPossibleCreatures(world, type, pos); return mobGenerator.getPossibleCreatures(world, type, pos);
} }
public final Biome getBiome(BiomeManager biomes, BlockPos pos) {
return super.getBiome(biomes, pos);
}
@Override @Override
public final int func_222529_a(int x, int z, Heightmap.Type type) { public final int func_222529_a(int x, int z, Heightmap.Type type) {
int chunkX = Size.blockToChunk(x); int chunkX = Size.blockToChunk(x);

View File

@ -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.column.ColumnDecorator;
import com.terraforged.api.chunk.surface.SurfaceManager; 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.FeatureManager;
import com.terraforged.mod.feature.manager.data.DataManager; import com.terraforged.mod.feature.manager.data.DataManager;
import com.terraforged.mod.feature.manager.matcher.biome.BiomeMatcher; 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.FeaturePredicate;
import com.terraforged.mod.feature.manager.predicate.MinDepth; import com.terraforged.mod.feature.manager.predicate.MinDepth;
import com.terraforged.mod.feature.manager.predicate.MinHeight; 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.material.geology.GeoManager;
import com.terraforged.mod.util.setup.SetupHooks; import com.terraforged.mod.util.setup.SetupHooks;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
@ -35,7 +34,7 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class TerraHooks { public class TerraSetupFactory {
public static DataManager createDataManager() { public static DataManager createDataManager() {
return FeatureManager.data(new File("config/terraforged/datapacks")); return FeatureManager.data(new File("config/terraforged/datapacks"));

View File

@ -27,7 +27,6 @@ package com.terraforged.mod.chunk.fix;
import com.terraforged.api.chunk.ChunkDelegate; import com.terraforged.api.chunk.ChunkDelegate;
import com.terraforged.api.material.state.States; import com.terraforged.api.material.state.States;
import com.terraforged.mod.material.MaterialHelper;
import com.terraforged.mod.material.Materials; import com.terraforged.mod.material.Materials;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -51,10 +50,10 @@ public class ChunkCarverFix implements ChunkDelegate {
@Override @Override
public BlockState getBlockState(BlockPos pos) { public BlockState getBlockState(BlockPos pos) {
BlockState state = getDelegate().getBlockState(pos); BlockState state = getDelegate().getBlockState(pos);
if (MaterialHelper.isAir(state.getBlock())) { if (materials.isAir(state.getBlock())) {
return state; return state;
} }
if (MaterialHelper.isGrass(state.getBlock())) { if (materials.isGrass(state.getBlock())) {
return States.GRASS_BLOCK.get(); return States.GRASS_BLOCK.get();
} }
if (materials.isStone(state.getBlock())) { if (materials.isStone(state.getBlock())) {

View File

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

View File

@ -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.core.region.chunk.ChunkReader;
import com.terraforged.world.terrain.decorator.Decorator; import com.terraforged.world.terrain.decorator.Decorator;

View File

@ -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.TerraChunkGenerator;
import com.terraforged.mod.chunk.fix.SpawnFix;
import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntityClassification;
import net.minecraft.util.SharedSeedRandom; import net.minecraft.util.SharedSeedRandom;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameRules;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.WorldGenRegion; 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.PatrolSpawner;
import net.minecraft.world.spawner.PhantomSpawner; import net.minecraft.world.spawner.PhantomSpawner;
import net.minecraft.world.spawner.WorldEntitySpawner; 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; import java.util.List;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
public class MobGenerator { public class MobGenerator {
// may be accessed cross-thread
private static volatile boolean mobSpawning = true;
private final CatSpawner catSpawner = new CatSpawner(); private final CatSpawner catSpawner = new CatSpawner();
private final PatrolSpawner patrolSpawner = new PatrolSpawner(); private final PatrolSpawner patrolSpawner = new PatrolSpawner();
private final PhantomSpawner phantomSpawner = new PhantomSpawner(); private final PhantomSpawner phantomSpawner = new PhantomSpawner();
@ -30,7 +37,7 @@ public class MobGenerator {
public final void generateMobs(WorldGenRegion region) { public final void generateMobs(WorldGenRegion region) {
// vanilla does NOT check the mobSpawning gamerule before calling this // vanilla does NOT check the mobSpawning gamerule before calling this
if (SpawnFix.canSpawnMobs()) { if (MobGenerator.mobSpawning) {
int chunkX = region.getMainChunkX(); int chunkX = region.getMainChunkX();
int chunkZ = region.getMainChunkZ(); int chunkZ = region.getMainChunkZ();
Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0); Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0);
@ -66,4 +73,11 @@ public class MobGenerator {
} }
return world.getBiome(pos).getSpawns(type); 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();
}
}
} }

View File

@ -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.TerraChunkGenerator;
import net.minecraft.network.DebugPacketSender; import net.minecraft.network.DebugPacketSender;
@ -9,7 +9,6 @@ import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeManager; import net.minecraft.world.biome.BiomeManager;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunk; import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.Feature;

View File

@ -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.TerraChunkGenerator;
import com.terraforged.mod.chunk.fix.ChunkCarverFix; import com.terraforged.mod.chunk.fix.ChunkCarverFix;

View File

@ -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.ColumnDecorator;
import com.terraforged.api.chunk.column.DecoratorContext; import com.terraforged.api.chunk.column.DecoratorContext;

View File

@ -31,7 +31,6 @@ import com.terraforged.api.material.layer.LayerManager;
import com.terraforged.api.material.layer.LayerMaterial; import com.terraforged.api.material.layer.LayerMaterial;
import com.terraforged.core.cell.Cell; import com.terraforged.core.cell.Cell;
import com.terraforged.world.heightmap.Levels; import com.terraforged.world.heightmap.Levels;
import com.terraforged.mod.material.MaterialHelper;
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.chunk.IChunk; 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 // if block is already a layer-type then simply set the layer property
BlockState state = chunk.getBlockState(context.pos); BlockState state = chunk.getBlockState(context.pos);
LayerMaterial material = layerManager.getMaterial(state.getBlock()); if (state.isAir(chunk, context.pos)) {
if (material != null) {
setLayer(chunk, context.pos, material, context.cell, context.levels, 0F);
return; 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; return;
} }
@ -65,7 +64,8 @@ public class LayerDecorator implements ColumnDecorator {
// block below is solid // block below is solid
if (chunk.getBlockState(context.pos.setPos(x, y, z)).getMaterial().blocksMovement()) { if (chunk.getBlockState(context.pos.setPos(x, y, z)).getMaterial().blocksMovement()) {
// block above is air // 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); // 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) { if (depth > min) {
int level = material.getLevel(depth); int level = material.getLevel(depth);
BlockState layer = material.getState(level); BlockState layer = material.getState(level);
if (MaterialHelper.isAir(layer.getBlock())) { if (layer == LayerMaterial.NONE) {
return; return;
} }
chunk.setBlockState(pos, layer, false); chunk.setBlockState(pos, layer, false);

View File

@ -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<Block> 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<DummyBlockReader> reader = DummyBlockReader.pooled()) {
reader.getValue().set(state);
return state.getBlockHardness(reader.getValue(), BlockPos.ZERO);
}
}
public static boolean isCube(BlockState state) {
try (ObjectPool.Item<DummyBlockReader> 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;
}
}

View File

@ -27,52 +27,31 @@ package com.terraforged.mod.material;
import com.terraforged.api.material.WGTags; import com.terraforged.api.material.WGTags;
import com.terraforged.api.material.layer.LayerManager; 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.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.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.Set;
import java.util.function.Predicate;
@Deprecated
public class Materials { public class Materials {
private final Set<Block> stone = create(WGTags.STONE); public final LayerManager layerManager = new LayerManager();
private final Set<Block> dirt = create(WGTags.DIRT); public final Set<Block> stone = create(WGTags.STONE, States.STONE.getBlock());
private final Set<Block> clay = create(WGTags.CLAY); public final Set<Block> dirt = create(WGTags.DIRT, States.DIRT.getBlock());
private final Set<Block> sediment = create(WGTags.SEDIMENT); public final Set<Block> clay = create(WGTags.CLAY, States.CLAY.getBlock());
private final Set<Block> erodible = create(WGTags.ERODIBLE); public final Set<Block> sediment = create(WGTags.SEDIMENT, States.GRAVEL.getBlock());
private final LayerManager layerManager = new LayerManager(); public final Set<Block> erodible = create(WGTags.ERODIBLE, null);
public Materials() {
Predicate<Block> 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 LayerManager getLayerManager() { public LayerManager getLayerManager() {
return layerManager; return layerManager;
@ -98,22 +77,30 @@ public class Materials {
return erodible.contains(block); return erodible.contains(block);
} }
private static Set<Block> create(Tag<Block> tag) { public boolean isAir(Block block) {
return new HashSet<>(tag.getAllElements()); return block instanceof AirBlock;
} }
private static Predicate<Block> getTagFilter() { public boolean isGrass(Block block) {
Set<String> namespaces = new HashSet<>(); return block instanceof GrassBlock || block instanceof MyceliumBlock;
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));
} }
private static void collectNamespace(Set<String> set, Collection<Block> blocks) { public boolean isSand(Block block) {
for (Block block : blocks) { return BlockTags.SAND.contains(block) && !(block instanceof ConcretePowderBlock);
set.add(MaterialHelper.getNamespace(block)); }
private static Set<Block> create(Tag<Block> tag, Block def) {
ObjectOpenHashSet<Block> 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<DummyBlockReader> reader = DummyBlockReader.pooled()) {
reader.getValue().set(state);
return state.getBlockHardness(reader.getValue(), BlockPos.ZERO);
} }
} }
} }

View File

@ -25,12 +25,10 @@
package com.terraforged.mod.material.geology; 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.StrataConfig;
import com.terraforged.api.material.geology.StrataGenerator; 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.mod.material.Materials;
import com.terraforged.world.geology.Strata;
import me.dags.noise.Source; import me.dags.noise.Source;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -50,10 +48,10 @@ public class GeoGenerator implements StrataGenerator {
public GeoGenerator(Materials materials) { public GeoGenerator(Materials materials) {
types.add(Source.PERLIN); types.add(Source.PERLIN);
rock = new ArrayList<>(WGTags.STONE.getAllElements()); rock = new ArrayList<>(materials.stone);
soil = new ArrayList<>(WGTags.DIRT.getAllElements()); soil = new ArrayList<>(materials.dirt);
clay = new ArrayList<>(WGTags.CLAY.getAllElements()); clay = new ArrayList<>(materials.clay);
sediment = new ArrayList<>(WGTags.SEDIMENT.getAllElements()); sediment = new ArrayList<>(materials.sediment);
} }
@Override @Override
@ -100,7 +98,7 @@ public class GeoGenerator implements StrataGenerator {
} }
private List<Layer> sortHardness(List<Layer> layers) { private List<Layer> sortHardness(List<Layer> layers) {
layers.sort(Comparator.comparing(s -> MaterialHelper.getHardness(s.state))); layers.sort(Comparator.comparing(s -> Materials.getHardness(s.state)));
return layers; return layers;
} }