Skip to content

Commit

Permalink
blooming stems can now grow
Browse files Browse the repository at this point in the history
  • Loading branch information
NewJumper committed Dec 12, 2024
1 parent f3a81e4 commit 02d96a8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21 2024-12-11T21:15:31.7389635 Registries
// 1.21 2024-12-12T16:46:10.7707931 Registries
65c8c67a4ec7ef0ce6846fb2f4d921cc6ceb02e2 data/deeperdarker/damage_type/bite.json
0b65c61bd1e5086d0f3685566cc6cecf6e324516 data/deeperdarker/damage_type/ring.json
dede162345c14db637f3dd9a20ca9319e037ae9d data/deeperdarker/dimension/otherside.json
Expand Down Expand Up @@ -67,7 +67,7 @@ ee40c6672e01f7903cbd018effd3b9fb238b9dc8 data/deeperdarker/worldgen/configured_f
333ebc366d7e8a080a71cde8f67a83af1f4daa8a data/deeperdarker/worldgen/configured_feature/water_edge_blooming.json
c7afaaec2673ebacca18346132ad25008799155c data/deeperdarker/worldgen/noise_settings/otherside.json
34fb9a5e22128132e9fb0b0a7700008873e4ac41 data/deeperdarker/worldgen/placed_feature/blooming_moss.json
75cae3824f63a98efdd5f8ea944c96f99864bc8e data/deeperdarker/worldgen/placed_feature/blooming_plant.json
c4020bc5fd1df4162e76204771b268958eb9c21a data/deeperdarker/worldgen/placed_feature/blooming_plant.json
7a014f12c936a2ce55cd0df3b6e7d66934996c63 data/deeperdarker/worldgen/placed_feature/blooming_pool.json
fe37fcf58645ddec579c794a106fbcff6e32c041 data/deeperdarker/worldgen/placed_feature/blooming_sculk_vegetation.json
7af28967be32198f89f2b307bdbd34274d1d555b data/deeperdarker/worldgen/placed_feature/blooming_water_edge.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"state": {
"Name": "deeperdarker:blooming_stem",
"Properties": {
"age": "0",
"down": "false",
"east": "false",
"north": "false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
private static final BlockSetType BLOOM_SET = BlockSetType.register(new BlockSetType("bloom"));
public static final WoodType BLOOM = WoodType.register(new WoodType("bloom", BLOOM_SET));

public static final DeferredBlock<Block> BLOOMING_STEM = register("blooming_stem", () -> new BloomingStemBlock(BlockBehaviour.Properties.of().strength(1f).sound(SoundType.WOOD).mapColor(MapColor.COLOR_CYAN).ignitedByLava().noOcclusion()));
public static final DeferredBlock<Block> BLOOMING_STEM = register("blooming_stem", () -> new BloomingStemBlock(BlockBehaviour.Properties.of().strength(1f).randomTicks().sound(SoundType.WOOD).mapColor(MapColor.COLOR_CYAN).ignitedByLava().noOcclusion()));
public static final DeferredBlock<Block> STRIPPED_BLOOMING_STEM = register("stripped_blooming_stem", () -> new BloomingStemBlock(BlockBehaviour.Properties.ofFullCopy(BLOOMING_STEM.get()).mapColor(MapColor.GLOW_LICHEN)));
public static final DeferredBlock<Block> BLOOM_PLANKS = register("bloom_planks", () -> new FlammableBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_PLANKS).mapColor(MapColor.GLOW_LICHEN), 20, 5));
public static final DeferredBlock<StairBlock> BLOOM_STAIRS = register("bloom_stairs", () -> new FlammableStairBlock(BLOOM_PLANKS.get().defaultBlockState(), BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_STAIRS).mapColor(MapColor.GLOW_LICHEN), 20, 5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
Expand All @@ -27,6 +28,7 @@

@SuppressWarnings("NullableProblems")
public class BloomingStemBlock extends Block {
public static final IntegerProperty AGE = BlockStateProperties.AGE_25;
public static final BooleanProperty UP = BlockStateProperties.UP;
public static final BooleanProperty DOWN = BlockStateProperties.DOWN;
public static final BooleanProperty NORTH = BlockStateProperties.NORTH;
Expand All @@ -45,12 +47,12 @@ public class BloomingStemBlock extends Block {

public BloomingStemBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(UP, false).setValue(DOWN, false).setValue(NORTH, false).setValue(EAST, false).setValue(SOUTH, false).setValue(WEST, false));
this.registerDefaultState(this.stateDefinition.any().setValue(AGE, 0).setValue(UP, false).setValue(DOWN, false).setValue(NORTH, false).setValue(EAST, false).setValue(SOUTH, false).setValue(WEST, false));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(UP, DOWN, NORTH, EAST, SOUTH, WEST);
builder.add(AGE, UP, DOWN, NORTH, EAST, SOUTH, WEST);
}

@Override
Expand All @@ -59,10 +61,10 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {
BlockGetter level = context.getLevel();

BlockState belowState = level.getBlockState(pos.below());
Direction clickedDir = context.getClickedFace();
Direction clickedFace = context.getClickedFace();

if(validBase(belowState)) return this.defaultBlockState().setValue(DOWN, true);
return this.defaultBlockState().setValue(PipeBlock.PROPERTY_BY_DIRECTION.get(clickedDir.getOpposite()), true);
return this.defaultBlockState().setValue(PipeBlock.PROPERTY_BY_DIRECTION.get(clickedFace.getOpposite()), true);
}

@Override
Expand Down Expand Up @@ -109,6 +111,48 @@ public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource
if(!state.canSurvive(level, pos)) level.destroyBlock(pos, true);
}

@Override
protected void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) {
if(state.getValue(AGE) >= 25) return;
if(!level.isEmptyBlock(pos.above())) return;
if(this.defaultBlockState().is(DDBlocks.STRIPPED_BLOOMING_STEM.get())) return;

int age = Math.min(25, state.getValue(AGE) + random.nextInt(1, 4));
state = state.setValue(AGE, age);
BlockState newState = this.defaultBlockState().setValue(AGE, age);
level.setBlock(pos, state, 3);

int connections = 0;
for(Direction direction : Direction.values()) {
if(state.getValue(PipeBlock.PROPERTY_BY_DIRECTION.get(direction))) connections++;
if(connections == 2) return;
}

if(random.nextFloat() < 0.05f) return;
if(connections == 1) {
if(state.getValue(DOWN) && random.nextFloat() < 0.3f) { // turn
Direction d1 = Direction.Plane.HORIZONTAL.getRandomDirection(random);

if(random.nextFloat() < 0.4f) { // branch
Direction d2 = Direction.getRandom(random);
if(random.nextFloat() < 0.5f) d2 = Direction.UP;
else while(d2 == Direction.DOWN || d2 == d1) d2 = Direction.getRandom(random);

if(level.isEmptyBlock(pos.relative(d2))) {
level.setBlock(pos.relative(d2), newState.setValue(PipeBlock.PROPERTY_BY_DIRECTION.get(d2.getOpposite()), true), 3);
}
}

if(level.isEmptyBlock(pos.relative(d1))) {
level.setBlock(pos.relative(d1), newState.setValue(PipeBlock.PROPERTY_BY_DIRECTION.get(d1.getOpposite()), true), 3);
return;
}
}

level.setBlock(pos.above(), newState.setValue(DOWN, true), 3);
}
}

@Override
public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
if(validBase(level.getBlockState(pos.below()))) return true;
Expand Down

0 comments on commit 02d96a8

Please sign in to comment.