use of net.minecraft.world.phys.shapes.CollisionContext in project blueprint by team-abnormals.
the class BlockUtil method canPlace.
/**
* Checks if a player can place a {@link BlockState} at a given {@link BlockPos} in a given {@link Level}.
*
* @param level A {@link Level} to use for checking the state at the given pos.
* @param player A {@link Player} to use for collision context, or null for no context.
* @param pos A {@link BlockPos} to check at.
* @param state A {@link BlockState} to check.
* @return If a player can place a {@link BlockState} at a given {@link BlockPos} in a given {@link Level}.
*/
public static boolean canPlace(Level level, @Nullable Player player, BlockPos pos, BlockState state) {
CollisionContext selectionContext = player == null ? CollisionContext.empty() : CollisionContext.of(player);
VoxelShape voxelshape = state.getCollisionShape(level, pos, selectionContext);
VoxelShape offsetShape = level.getBlockState(pos).getCollisionShape(level, pos);
return (offsetShape.isEmpty() || level.getBlockState(pos).getMaterial().isReplaceable()) && state.canSurvive(level, pos) && level.isUnobstructed(null, voxelshape.move(pos.getX(), pos.getY(), pos.getZ()));
}
use of net.minecraft.world.phys.shapes.CollisionContext in project TerraFirmaCraft by TerraFirmaCraft.
the class BlockItemPlacement method canPlace.
protected boolean canPlace(BlockPlaceContext context, BlockState stateToPlace) {
Player player = context.getPlayer();
CollisionContext selectionContext = player == null ? CollisionContext.empty() : CollisionContext.of(player);
return (stateToPlace.canSurvive(context.getLevel(), context.getClickedPos())) && context.getLevel().isUnobstructed(stateToPlace, context.getClickedPos(), selectionContext);
}
use of net.minecraft.world.phys.shapes.CollisionContext in project Create by Creators-of-Create.
the class BeltTunnelItem method canPlace.
@Override
protected boolean canPlace(BlockPlaceContext ctx, BlockState state) {
Player playerentity = ctx.getPlayer();
CollisionContext iselectioncontext = playerentity == null ? CollisionContext.empty() : CollisionContext.of(playerentity);
Level world = ctx.getLevel();
BlockPos pos = ctx.getClickedPos();
return (!this.mustSurvive() || AllBlocks.ANDESITE_TUNNEL.get().isValidPositionForPlacement(state, world, pos)) && world.isUnobstructed(state, pos, iselectioncontext);
}
Aggregations