Skip to content

Commit

Permalink
fixed blooming stem functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
NewJumper committed Nov 1, 2023
1 parent 81412e7 commit 66472e5
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ public BlockState getStateForPlacement(BlockPlaceContext pContext) {
BlockPos pos = pContext.getClickedPos();
BlockGetter level = pContext.getLevel();

BlockState aboveState = level.getBlockState(pos.above());
BlockState belowState = level.getBlockState(pos.below());
BlockState northState = level.getBlockState(pos.north());
BlockState eastState = level.getBlockState(pos.east());
BlockState southState = level.getBlockState(pos.south());
BlockState westState = level.getBlockState(pos.west());

if(belowState.is(this) || belowState.is(DDBlocks.BLOOMING_SCULK.get())) return this.defaultBlockState();
return this.defaultBlockState().setValue(UP, aboveState.is(this)).setValue(DOWN, belowState.is(this) || belowState.is(DDBlocks.BLOOMING_SCULK.get())).setValue(NORTH, northState.is(this)).setValue(EAST, eastState.is(this)).setValue(SOUTH, southState.is(this)).setValue(WEST, westState.is(this));
return this.defaultBlockState().setValue(DOWN, belowState.is(this) || belowState.is(DDBlocks.BLOOMING_SCULK.get())).setValue(NORTH, northState.is(this)).setValue(EAST, eastState.is(this)).setValue(SOUTH, southState.is(this)).setValue(WEST, westState.is(this));
}

@Override
Expand All @@ -86,30 +85,23 @@ public BlockState updateShape(BlockState pState, Direction pDirection, BlockStat
}

if(pDirection == Direction.DOWN && pNeighborState.is(DDBlocks.BLOOMING_SCULK.get())) return pState.setValue(DOWN, true);
if(pDirection.getAxis().isHorizontal() && !pLevel.getBlockState(pNeighborPos.below()).isAir()) return pState;
if(pDirection.getAxis().isHorizontal() && pNeighborState.is(this) && canSurvive(pLevel.getBlockState(pNeighborPos.below()))) return pState;
return pState.setValue(PipeBlock.PROPERTY_BY_DIRECTION.get(pDirection), pNeighborState.is(this));
}

@Override
public void tick(BlockState pState, ServerLevel pLevel, BlockPos pPos, RandomSource pRandom) {
if(!pState.canSurvive(pLevel, pPos)) {
pLevel.destroyBlock(pPos, true);
}
if(!pState.canSurvive(pLevel, pPos)) pLevel.destroyBlock(pPos, true);
}

@Override
public boolean canSurvive(BlockState pState, LevelReader pLevel, BlockPos pPos) {
BlockState below = pLevel.getBlockState(pPos.below());

if(below.is(this) || below.is(DDBlocks.BLOOMING_SCULK.get())) return true;


if(canSurvive(below)) return true;

for(Direction direction : Direction.Plane.HORIZONTAL) {
BlockPos pos = pPos.relative(direction);
BlockState state = pLevel.getBlockState(pos);
if(state.is(this) && canSurvive(pLevel.getBlockState(pos.below()))) return true;
if(state.is(this) && pState.getValue(PipeBlock.PROPERTY_BY_DIRECTION.get(direction)) && canSurvive(pLevel.getBlockState(pos.below()))) return true;
}

return false;
Expand Down

0 comments on commit 66472e5

Please sign in to comment.