-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/generated/resources/data/deeperdarker/worldgen/configured_feature/glowing_roots.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "deeperdarker:glowing_roots", | ||
"config": {} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/generated/resources/data/deeperdarker/worldgen/placed_feature/glowing_roots.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"feature": "deeperdarker:glowing_roots", | ||
"placement": [ | ||
{ | ||
"type": "minecraft:count", | ||
"count": 58 | ||
}, | ||
{ | ||
"type": "minecraft:in_square" | ||
}, | ||
{ | ||
"type": "minecraft:height_range", | ||
"height": { | ||
"type": "minecraft:uniform", | ||
"max_inclusive": { | ||
"below_top": 0 | ||
}, | ||
"min_inclusive": { | ||
"above_bottom": 0 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "minecraft:biome" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/com/kyanite/deeperdarker/world/features/GlowingRootsFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.kyanite.deeperdarker.world.features; | ||
|
||
import com.kyanite.deeperdarker.content.DDBlocks; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.LevelAccessor; | ||
import net.minecraft.world.level.WorldGenLevel; | ||
import net.minecraft.world.level.block.GrowingPlantHeadBlock; | ||
import net.minecraft.world.level.levelgen.feature.Feature; | ||
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; | ||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; | ||
|
||
public class GlowingRootsFeature extends Feature<NoneFeatureConfiguration> { | ||
public GlowingRootsFeature(Codec<NoneFeatureConfiguration> pCodec) { | ||
super(pCodec); | ||
} | ||
|
||
@Override | ||
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> pContext) { | ||
WorldGenLevel level = pContext.level(); | ||
BlockPos origin = pContext.origin(); | ||
RandomSource random = pContext.random(); | ||
|
||
if(!isValidPlacementLocation(level, origin)) return false; | ||
|
||
int width = 5; | ||
int height = 3; | ||
int maxHeight = 6; | ||
BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(); | ||
for(int i = 0; i < width * width; i++) { | ||
blockPos.set(origin).move(Mth.nextInt(random, -width, width), Mth.nextInt(random, -height, height), Mth.nextInt(random, -width, width)); | ||
if(findAirAboveGround(level, blockPos) && isValidPlacementLocation(level, blockPos)) { | ||
int length = random.nextInt(1, maxHeight); | ||
if(random.nextInt(12) == 0) length *= 2; | ||
if(random.nextInt(6) == 0) length = 1; | ||
placeColumn(level, random, blockPos, length); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private boolean isValidPlacementLocation(LevelAccessor level, BlockPos pos) { | ||
return level.getBlockState(pos.below()).is(DDBlocks.BLOOMING_SCULK_STONE.get()); | ||
} | ||
|
||
private boolean findAirAboveGround(LevelAccessor level, BlockPos.MutableBlockPos pos) { | ||
do { | ||
pos.move(0, -1, 0); | ||
if(level.isOutsideBuildHeight(pos)) return false; | ||
} while(level.getBlockState(pos).isAir()); | ||
|
||
pos.move(0, 1, 0); | ||
return true; | ||
} | ||
|
||
private void placeColumn(LevelAccessor level, RandomSource random, BlockPos.MutableBlockPos pos, int length) { | ||
for(int i = 1; i <= length; i++) { | ||
if(level.isEmptyBlock(pos)) { | ||
if(i == length || !level.isEmptyBlock(pos.above())) { | ||
level.setBlock(pos, DDBlocks.GLOWING_ROOTS.get().defaultBlockState().setValue(GrowingPlantHeadBlock.AGE, random.nextIntBetweenInclusive(17, 25)), 3); | ||
break; | ||
} | ||
|
||
level.setBlock(pos, DDBlocks.GLOWING_ROOTS_PLANT.get().defaultBlockState(), 3); | ||
} | ||
|
||
pos.move(Direction.UP); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters