Skip to content

Commit

Permalink
feat: Add Quicksand Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Drullkus committed Dec 29, 2021
1 parent a3c3c30 commit 372d75a
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/generated/resources/.cache/cache
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ ef1688d8839282e91b8aa07f3029cefcf02df64e data/aether/tags/items/skyroot_stick.js
999af6754446aa73b45312bf631ed4ac234ec764 data/aether/tags/items/trapped_dungeon_blocks.json
8f8f0e16bb000c5f7503a95c7fcf7b19e42774af data/aether/tags/items/valkyrie_tools.json
7857dbef719f59695d7f3f80ae5a7b2090dabd97 data/aether/tags/items/zanite_tools.json
7ab1c61c6e05d700eb32196c3afc7f25587e72f7 data/aether/worldgen/biome/floating_forest.json
ad1187cef647fd2cd91aa775a5b834642c93701d data/aether/worldgen/biome/floating_forest.json
f6339302eee532026dfae6480f2a71498c8a469c data/aether/worldgen/noise_settings/skyland_generation.json
4eca19e7372c333e02a61b39149536f67bada489 data/forge/tags/blocks/dirt.json
ef896638976d84e49ea64f3df732b1fa877600bb data/forge/tags/blocks/fence_gates/wooden.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
{
"carvers": {},
"features": [
[],
[
{
"feature": {
"config": {
"radius": 3.4641016,
"block": {
"state": {
"Properties": {
"double_drops": "true"
},
"Name": "aether:quicksoil"
},
"type": "minecraft:simple_state_provider"
},
"clearance_radius": 3
},
"type": "aether:simple_disk"
},
"placement": [
{
"count": 10,
"type": "minecraft:count"
},
{
"type": "minecraft:in_square"
},
{
"height": {
"min_inclusive": {
"absolute": 10
},
"max_inclusive": {
"absolute": 70
},
"type": "minecraft:trapezoid"
},
"type": "minecraft:height_range"
}
]
}
],
[],
[],
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gildedgames.aether.Aether;
import com.gildedgames.aether.common.block.state.properties.AetherBlockStateProperties;
import com.gildedgames.aether.common.world.gen.configuration.AercloudConfiguration;
import com.gildedgames.aether.common.world.gen.configuration.SimpleDiskConfiguration;
import com.gildedgames.aether.common.world.gen.feature.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -27,7 +28,7 @@ public class AetherFeatures
//
// public static final RegistryObject<Feature<RandomPatchConfiguration>> GRASS_PATCH = FEATURES.register("grass_patch", () -> new AetherGrassFeature(RandomPatchConfiguration.CODEC));
//
// public static final RegistryObject<Feature<NoneFeatureConfiguration>> QUICKSOIL = FEATURES.register("quicksoil", () -> new QuicksoilFeature(NoneFeatureConfiguration.CODEC));
public static final RegistryObject<Feature<SimpleDiskConfiguration>> SIMPLE_DISK = FEATURES.register("simple_disk", () -> new SimpleDiskFeature(SimpleDiskConfiguration.CODEC));
//
// public static final RegistryObject<Feature<BlockStateConfiguration>> LAKE = FEATURES.register("lake", () -> new AetherLakeFeature(BlockStateConfiguration.CODEC));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.gildedgames.aether.common.world.gen.configuration;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;

public record SimpleDiskConfiguration(float radius, BlockStateProvider block, int clearanceRadius) implements FeatureConfiguration {
public static final Codec<SimpleDiskConfiguration> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.floatRange(1, 12).fieldOf("radius").forGetter(SimpleDiskConfiguration::radius),
BlockStateProvider.CODEC.fieldOf("block").forGetter(SimpleDiskConfiguration::block),
Codec.intRange(1, 12).fieldOf("clearance_radius").forGetter(SimpleDiskConfiguration::clearanceRadius)
).apply(instance, SimpleDiskConfiguration::new));
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gildedgames.aether.common.world.gen.feature;

import com.gildedgames.aether.common.registry.AetherBlocks;
import com.gildedgames.aether.common.registry.AetherTags;
import com.gildedgames.aether.common.world.gen.configuration.SimpleDiskConfiguration;
import com.gildedgames.aether.core.util.BlockLogic;
import com.gildedgames.aether.core.util.BlockPlacers;
import com.mojang.serialization.Codec;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;

public class SimpleDiskFeature extends Feature<SimpleDiskConfiguration> {
public SimpleDiskFeature(Codec<SimpleDiskConfiguration> codec) {
super(codec);
}

@Override
public boolean place(FeaturePlaceContext<SimpleDiskConfiguration> context) {
BlockPos pos = context.origin();
WorldGenLevel reader = context.level();

boolean doesProtrude = BlockLogic.doesAirExistNearby(pos, context.config().clearanceRadius(), reader) &&
(reader.getBlockState(pos).is(AetherTags.Blocks.HOLYSTONE) ||
reader.getBlockState(pos).getBlock() == AetherBlocks.AETHER_DIRT.get());

if (doesProtrude)
BlockPlacers.placeDisk(pos, context.config().radius(), reader, context.config().block(), context.random());

return doesProtrude;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.gildedgames.aether.core.data;

import com.gildedgames.aether.common.block.state.properties.AetherBlockStateProperties;
import com.gildedgames.aether.common.registry.AetherBlocks;
import com.gildedgames.aether.common.registry.AetherFeatures;
import com.gildedgames.aether.common.world.gen.configuration.AercloudConfiguration;
import com.gildedgames.aether.common.world.gen.configuration.SimpleDiskConfiguration;
import com.gildedgames.aether.core.data.provider.AetherFeatureDataProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.data.worldgen.features.FeatureUtils;
import net.minecraft.data.worldgen.features.VegetationFeatures;
import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.data.worldgen.placement.VegetationPlacements;
import net.minecraft.util.Mth;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.util.valueproviders.ConstantInt;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration;
Expand All @@ -24,7 +20,6 @@
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.levelgen.feature.stateproviders.SimpleStateProvider;
import net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider;
import net.minecraft.world.level.levelgen.feature.trunkplacers.FancyTrunkPlacer;
import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlacer;
Expand All @@ -34,63 +29,54 @@

public class AetherFeatureData {

public static final ConfiguredFeature COLD_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
public static final ConfiguredFeature<AercloudConfiguration, ?> COLD_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
.configured(AetherFeatureDataProvider.createAercloudConfig(16, AetherBlocks.COLD_AERCLOUD.get().defaultBlockState()));

public static final ConfiguredFeature BLUE_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
public static final ConfiguredFeature<AercloudConfiguration, ?> BLUE_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
.configured(AetherFeatureDataProvider.createAercloudConfig(8, AetherBlocks.BLUE_AERCLOUD.get().defaultBlockState()));

public static final ConfiguredFeature GOLDEN_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
public static final ConfiguredFeature<AercloudConfiguration, ?> GOLDEN_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
.configured(AetherFeatureDataProvider.createAercloudConfig(4, AetherBlocks.GOLDEN_AERCLOUD.get().defaultBlockState()));

public static final ConfiguredFeature PINK_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
public static final ConfiguredFeature<AercloudConfiguration, ?> PINK_AERCLOUD_FEATURE_BASE = AetherFeatures.AERCLOUD.get()
.configured(AetherFeatureDataProvider.createAercloudConfig(1, AetherBlocks.PINK_AERCLOUD.get().defaultBlockState()));

public static final ConfiguredFeature SKYROOT_TREE_FEATURE_BASE = Feature.TREE.configured(new TreeConfiguration.TreeConfigurationBuilder(
BlockStateProvider.simple(getDoubleDrops(AetherBlocks.SKYROOT_LOG.get())),
public static final ConfiguredFeature<TreeConfiguration, ?> SKYROOT_TREE_FEATURE_BASE = Feature.TREE.configured(new TreeConfiguration.TreeConfigurationBuilder(
BlockStateProvider.simple(AetherFeatureDataProvider.getDoubleDrops(AetherBlocks.SKYROOT_LOG)),
new StraightTrunkPlacer(4, 2, 0),
BlockStateProvider.simple(getDoubleDrops(AetherBlocks.SKYROOT_LEAVES.get())),
BlockStateProvider.simple(AetherFeatureDataProvider.getDoubleDrops(AetherBlocks.SKYROOT_LEAVES)),
new BlobFoliagePlacer(ConstantInt.of(2), ConstantInt.of(0), 3),
new TwoLayersFeatureSize(1, 0, 1)).ignoreVines().build());

public static final ConfiguredFeature GOLDEN_OAK_FEATURE_BASE = Feature.TREE.configured(new TreeConfiguration.TreeConfigurationBuilder(
BlockStateProvider.simple(getDoubleDrops(AetherBlocks.GOLDEN_OAK_LOG.get())),
public static final ConfiguredFeature<TreeConfiguration, ?> GOLDEN_OAK_FEATURE_BASE = Feature.TREE.configured(new TreeConfiguration.TreeConfigurationBuilder(
BlockStateProvider.simple(AetherFeatureDataProvider.getDoubleDrops(AetherBlocks.GOLDEN_OAK_LOG)),
new FancyTrunkPlacer(3, 11, 0),
BlockStateProvider.simple(getDoubleDrops(AetherBlocks.GOLDEN_OAK_LEAVES.get())),
BlockStateProvider.simple(AetherFeatureDataProvider.getDoubleDrops(AetherBlocks.GOLDEN_OAK_LEAVES.get())),
new FancyFoliagePlacer(ConstantInt.of(2), ConstantInt.of(4), 4),
new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))).build());

public static final ConfiguredFeature<RandomPatchConfiguration, ?> FLOWER_FEATURE_BASE = Feature.FLOWER.configured(AetherFeatureDataProvider.grassPatch(
new WeightedStateProvider(SimpleWeightedRandomList.<BlockState>builder()
.add(AetherBlocks.PURPLE_FLOWER.get().defaultBlockState(), 2)
.add(AetherBlocks.WHITE_FLOWER.get().defaultBlockState(), 2)
.add(getDoubleDrops(AetherBlocks.BERRY_BUSH.get()), 1)), 64));
.add(AetherFeatureDataProvider.getDoubleDrops(AetherBlocks.BERRY_BUSH), 1)), 64));

public static final ConfiguredFeature<SimpleDiskConfiguration, ?> QUICKSOIL_BASE = AetherFeatures.SIMPLE_DISK.get().configured(new SimpleDiskConfiguration(
Mth.sqrt(12), // Yes, this is what the math works out to - Drull TODO Randomize
BlockStateProvider.simple(AetherFeatureDataProvider.getDoubleDrops(AetherBlocks.QUICKSOIL)),
3
));

public static final PlacedFeature COLD_AERCLOUD_FEATURE = COLD_AERCLOUD_FEATURE_BASE.placed(
AetherFeatureDataProvider.createAercloudPlacements(128, 5));

public static final PlacedFeature BLUE_AERCLOUD_FEATURE = BLUE_AERCLOUD_FEATURE_BASE.placed(
AetherFeatureDataProvider.createAercloudPlacements(96, 5));

public static final PlacedFeature GOLDEN_AERCLOUD_FEATURE = GOLDEN_AERCLOUD_FEATURE_BASE.placed(
AetherFeatureDataProvider.createAercloudPlacements(160, 5));

public static final PlacedFeature PINK_AERCLOUD_FEATURE = PINK_AERCLOUD_FEATURE_BASE.placed(
AetherFeatureDataProvider.createAercloudPlacements(160, 7));

public static final PlacedFeature SKYROOT_TREE_FEATURE = SKYROOT_TREE_FEATURE_BASE.placed(VegetationPlacements.treePlacement(PlacementUtils.countExtra(6, 0.1F, 1), AetherBlocks.SKYROOT_SAPLING.get()));

public static final PlacedFeature GOLDEN_OAK_TREE_FEATURE = GOLDEN_OAK_FEATURE_BASE.placed(VegetationPlacements.treePlacement(PlacementUtils.countExtra(1, 0.1F, 1), AetherBlocks.GOLDEN_OAK_SAPLING.get()));

public static final PlacedFeature FLOWER_FEATURE = FLOWER_FEATURE_BASE.placed(InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP, BiomeFilter.biome());

public static BlockState getDoubleDrops(Block block) {
return getDoubleDrops(block.defaultBlockState());
}

public static BlockState getDoubleDrops(BlockState blockState) {
return blockState.setValue(AetherBlockStateProperties.DOUBLE_DROPS, true);
}


public static final PlacedFeature QUICKSOIL_FEATURE = QUICKSOIL_BASE.placed(CountPlacement.of(10), InSquarePlacement.spread(), HeightRangePlacement.triangle(VerticalAnchor.absolute(10), VerticalAnchor.absolute(70))); // TODO Improve cliff detection mechanism
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Biome makeDefaultBiome() {
.build(),
new BiomeGenerationSettings.Builder()
// TODO GenerationStep.Decoration.RAW_GENERATION
// "aether:quicksoil"
.addFeature(GenerationStep.Decoration.RAW_GENERATION, AetherFeatureData.QUICKSOIL_FEATURE)
// "aether:crystal_tree"
// TODO GenerationStep.Decoration.LAKES
// "aether:water_lake"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gildedgames.aether.common.block.state.properties.AetherBlockStateProperties;
import com.gildedgames.aether.common.world.gen.configuration.AercloudConfiguration;
import net.minecraft.data.worldgen.features.FeatureUtils;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.feature.Feature;
Expand All @@ -12,6 +13,7 @@
import net.minecraft.world.level.levelgen.placement.*;

import java.util.List;
import java.util.function.Supplier;

public class AetherFeatureDataProvider {

Expand All @@ -29,4 +31,16 @@ public static List<PlacementModifier> createAercloudPlacements(int height, int c
public static RandomPatchConfiguration grassPatch(BlockStateProvider p_195203_, int p_195204_) {
return FeatureUtils.simpleRandomPatchConfiguration(p_195204_, Feature.SIMPLE_BLOCK.configured(new SimpleBlockConfiguration(p_195203_)).onlyWhenEmpty());
}

public static BlockState getDoubleDrops(Supplier<? extends Block> block) {
return getDoubleDrops(block.get());
}

public static BlockState getDoubleDrops(Block block) {
return getDoubleDrops(block.defaultBlockState());
}

public static BlockState getDoubleDrops(BlockState blockState) {
return blockState.setValue(AetherBlockStateProperties.DOUBLE_DROPS, true);
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/gildedgames/aether/core/util/BlockLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.gildedgames.aether.core.util;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;

public final class BlockLogic {
public static boolean doesAirExistNearby(BlockPos center, int radius, WorldGenLevel level) {
return level.isEmptyBlock(center.north(radius))
|| level.isEmptyBlock(center.south(radius))
|| level.isEmptyBlock(center.west(radius))
|| level.isEmptyBlock(center.east(radius));
}

private BlockLogic() {
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/gildedgames/aether/core/util/BlockPlacers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.gildedgames.aether.core.util;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;

import java.util.Random;

public final class BlockPlacers {
public static void placeDisk(BlockPos center, float radius, WorldGenLevel level, BlockStateProvider blockProvider, Random random) {
float radiusSq = radius * radius;

placeProvidedBlock(level, blockProvider, center, random);

for (int z = 1; z < radius; z++) {
for (int x = 0; x < radius; x++) {
if (x * x + z * z > radiusSq) continue;

placeProvidedBlock(level, blockProvider, center.offset(x, 0, z), random);
placeProvidedBlock(level, blockProvider, center.offset(-x, 0, -z), random);
placeProvidedBlock(level, blockProvider, center.offset(-z, 0, x), random);
placeProvidedBlock(level, blockProvider, center.offset(z, 0, -x), random);
}
}
}

@SuppressWarnings("UnusedReturnValue") // Retain the boolean feedback from setting block
public static boolean placeProvidedBlock(WorldGenLevel level, BlockStateProvider provider, BlockPos pos, Random random) {
return level.setBlock(pos, provider.getState(random, pos), 2);
}

private BlockPlacers() {
}
}

0 comments on commit 372d75a

Please sign in to comment.