Skip to content

Commit

Permalink
blooming stems are now bonemealable
Browse files Browse the repository at this point in the history
  • Loading branch information
NewJumper committed Dec 13, 2024
1 parent 02d96a8 commit 621ff3a
Showing 1 changed file with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.PipeBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
Expand All @@ -27,7 +29,7 @@
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("NullableProblems")
public class BloomingStemBlock extends Block {
public class BloomingStemBlock extends Block implements BonemealableBlock {
public static final IntegerProperty AGE = BlockStateProperties.AGE_25;
public static final BooleanProperty UP = BlockStateProperties.UP;
public static final BooleanProperty DOWN = BlockStateProperties.DOWN;
Expand Down Expand Up @@ -114,14 +116,14 @@ public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource
@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);

if(!level.isEmptyBlock(pos.above())) return;
if(this.defaultBlockState().is(DDBlocks.STRIPPED_BLOOMING_STEM.get())) return;

int connections = 0;
for(Direction direction : Direction.values()) {
if(state.getValue(PipeBlock.PROPERTY_BY_DIRECTION.get(direction))) connections++;
Expand Down Expand Up @@ -173,4 +175,37 @@ private boolean validBase(BlockState state) {
private boolean isStem(BlockState state) {
return state.is(DDTags.Blocks.BLOOM_STEMS);
}

@Override
public boolean isValidBonemealTarget(LevelReader level, BlockPos pos, BlockState state) {
if(state.is(DDBlocks.STRIPPED_BLOOMING_STEM.get())) return false;
if(level.isEmptyBlock(pos.above())) return true;
if(!state.getValue(DOWN)) return false;
for(Direction direction : Direction.Plane.HORIZONTAL) {
if(level.isEmptyBlock(pos.relative(direction))) return true;
}

return false;
}

@Override
public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) {
return true;
}

@Override
public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) {
BlockState newState = this.defaultBlockState().setValue(AGE, state.getValue(AGE));
if(level.isEmptyBlock(pos.above())) {
level.setBlock(pos.above(), newState.setValue(DOWN, true), 3);
return;
}

for(Direction direction : Direction.Plane.HORIZONTAL) {
if(level.isEmptyBlock(pos.relative(direction))) {
level.setBlock(pos.relative(direction), newState.setValue(PipeBlock.PROPERTY_BY_DIRECTION.get(direction.getOpposite()), true), 3);
return;
}
}
}
}

0 comments on commit 621ff3a

Please sign in to comment.