Skip to content

Commit

Permalink
feat: make Primal Bloom placeable on all primal block variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Mar 16, 2024
1 parent 4a2a319 commit 44f7f9f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.elenterius.biomancy.block.bloom;

import com.github.elenterius.biomancy.block.base.WaterloggedFacingBlock;
import com.github.elenterius.biomancy.init.ModBlocks;
import com.github.elenterius.biomancy.init.ModItems;
import com.github.elenterius.biomancy.init.ModPlantTypes;
import com.github.elenterius.biomancy.init.ModProjectiles;
Expand Down Expand Up @@ -174,21 +173,15 @@ public BlockState updateShape(BlockState state, Direction direction, BlockState
return !state.canSurvive(level, currentPos) ? Blocks.AIR.defaultBlockState() : super.updateShape(state, direction, neighborState, level, currentPos, neighborPos);
}

public boolean mayPlaceOn(BlockGetter level, BlockPos pos, BlockState state) {
return state.is(ModBlocks.PRIMAL_FLESH.get()) || state.is(ModBlocks.MALIGNANT_FLESH.get());
public boolean mayPlaceOn(BlockGetter level, BlockPos pos, BlockState state, Direction facing) {
return state.canSustainPlant(level, pos, facing, this);
}

@Override
public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
Direction direction = state.getValue(FACING);
BlockPos blockPos = pos.relative(direction.getOpposite());

if (state.getBlock() == this) {
//world gen and placement
return level.getBlockState(blockPos).canSustainPlant(level, blockPos, direction, this);
}

return mayPlaceOn(level, blockPos, level.getBlockState(blockPos));
return mayPlaceOn(level, blockPos, level.getBlockState(blockPos), direction);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected static boolean convertSelfIntoBloom(ServerLevel level, BlockPos pos, D

BlockPos posBelow = pos.relative(direction);
BlockState stateBelow = level.getBlockState(posBelow);
boolean mayPlace = bloomBlock.mayPlaceOn(level, posBelow, stateBelow);
boolean mayPlace = bloomBlock.mayPlaceOn(level, posBelow, stateBelow, Direction.UP);

if (mayPlace && !LevelUtil.isBlockNearby(level, pos, 4, blockState -> blockState.is(bloomBlock)) && bloomBlock.hasUnobstructedAim(level, pos, direction.getOpposite())) {
BlockState stateForPlacement = bloomBlock.getStateForPlacement(level, pos, direction.getOpposite());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static boolean placeBloomOrBlocks(ServerLevel level, BlockPos pos, Direct
BlockState relativeState = level.getBlockState(relativePos);
RandomSource random = level.getRandom();

if (random.nextFloat() < 0.7f && ModBlocks.PRIMAL_BLOOM.get().mayPlaceOn(level, pos, state)) {
if (random.nextFloat() < 0.7f && ModBlocks.PRIMAL_BLOOM.get().mayPlaceOn(level, pos, state, direction)) {
boolean canBeReplaced = relativeState.canBeReplaced(new DirectionalPlaceContext(level, relativePos, direction.getOpposite(), ItemStack.EMPTY, direction));
boolean noBloomNearby = !LevelUtil.isBlockNearby(level, pos, 4, blockState -> blockState.is(ModBlocks.PRIMAL_BLOOM.get()));
if (canBeReplaced && noBloomNearby) {
Expand Down

0 comments on commit 44f7f9f

Please sign in to comment.