net.minecraft.block.Block.canSustainPlant()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中net.minecraft.block.Block.canSustainPlant()方法的一些代码示例,展示了Block.canSustainPlant()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.canSustainPlant()方法的具体详情如下:
包路径:net.minecraft.block.Block
类名称:Block
方法名:canSustainPlant

Block.canSustainPlant介绍

暂无

代码示例

代码示例来源:origin: SlimeKnights/TinkersConstruct

public void generateTree(Random random, World world, BlockPos pos) {
 int height = random.nextInt(this.treeHeightRange) + this.minTreeHeight;
 boolean flag = true;
 if(seekHeight) {
  pos = findGround(world, pos);
  if(pos.getY() < 0) {
   return;
  }
 }
 int yPos = pos.getY();
 if(yPos >= 1 && yPos + height + 1 <= 256) {
  IBlockState state = world.getBlockState(pos.down());
  Block soil = state.getBlock();
  boolean isSoil = (soil != Blocks.AIR && soil.canSustainPlant(state, world, pos.down(), EnumFacing.UP, TinkerWorld.slimeSapling));
  if(isSoil) {
   soil.onPlantGrow(state, world, pos.down(), pos);
   placeCanopy(world, random, pos, height);
   placeTrunk(world, pos, height);
  }
 }
}

代码示例来源:origin: Vazkii/Botania

@Override
public boolean canBlockStay(@Nonnull World worldIn, BlockPos pos, IBlockState state)
{
  if (pos.getY() >= 0 && pos.getY() < 256)
  {
    IBlockState iblockstate = worldIn.getBlockState(pos.down());
    return iblockstate.getBlock() == Blocks.MYCELIUM
        || (iblockstate.getBlock() == Blocks.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL
        || iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this));
  }
  else
  {
    return false;
  }
}

代码示例来源:origin: SlimeKnights/TinkersConstruct

if(down.getBlock().canSustainPlant(down, world, pos.down(), EnumFacing.UP, seed)) {

代码示例来源:origin: MatrexsVigil/harvestcraft

private static boolean canHarvestCrops(IBlockState plantBlockState, World world, BlockPos pos) {
  if(!(plantBlockState.getBlock() instanceof BlockCrops)) return false;
  final BlockCrops crops = (BlockCrops) plantBlockState.getBlock();
  IBlockState soilBlockState = world.getBlockState(pos.down());
  if(!soilBlockState.getBlock().canSustainPlant(soilBlockState, world, pos.down(), EnumFacing.UP, crops)) return false;
  return crops.isMaxAge(plantBlockState);
}

代码示例来源:origin: SleepyTrousers/EnderIO

protected boolean canPlant(@Nonnull IFarmer farm, @Nonnull World world, @Nonnull BlockPos bc, @Nonnull IPlantable plantable) {
 IBlockState target = getPlant(farm, plantable);
 BlockPos groundPos = bc.down();
 IBlockState groundBS = world.getBlockState(groundPos);
 Block ground = groundBS.getBlock();
 if (target != null && target.getBlock().canPlaceBlockAt(world, bc) && ground.canSustainPlant(groundBS, world, groundPos, EnumFacing.UP, plantable)) {
  return true;
 }
 return false;
}

代码示例来源:origin: ForestryMC/ForestryMC

@Override
public boolean canStay(IBlockAccess world, BlockPos pos) {
  BlockPos blockPos = pos.down();
  IBlockState blockState = world.getBlockState(blockPos);
  Block block = blockState.getBlock();
  return block.canSustainPlant(blockState, world, blockPos, EnumFacing.UP, this);
}

代码示例来源:origin: PenguinSquad/Harvest-Festival

/** Returns true if this seed can be planted at this block position
 *  @param world    the world
 *  @param pos      the position to be planted
 *  @param soil     the state of the block clicked on
 *  @param crop     the crop itself
 *  @param original the original position clicked**/
public boolean canPlantSeedAt(World world, BlockPos pos, IBlockState soil, C crop, BlockPos original) {
  return soil != Blocks.AIR && soil.getBlock().canSustainPlant(soil, world, pos, EnumFacing.UP, crop) && world.isAirBlock(pos.up());
}

代码示例来源:origin: RS485/LogisticsPipes

@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) {
  Block block = mcmpBlockAccess.getBlock();
  return block != null ? block.canSustainPlant(state, world, pos, direction, plantable) : super.canSustainPlant(state, world, pos, direction, plantable);
}

代码示例来源:origin: SleepyTrousers/EnderIO

protected boolean canPlant(@Nonnull IFarmer farm, @Nonnull World world, @Nonnull BlockPos bc) {
 Block target = getPlantedBlock();
 BlockPos groundPos = bc.down();
 IBlockState bs = world.getBlockState(groundPos);
 Block ground = bs.getBlock();
 IPlantable plantable = (IPlantable) getPlantedBlock();
 if (target.canPlaceBlockAt(world, bc) && (ground.canSustainPlant(bs, world, groundPos, EnumFacing.UP, plantable) || ignoreSustainCheck)
   && (!isCheckGroundForFarmland() || isGroundTilled(farm, bc))) {
  return true;
 }
 return false;
}

代码示例来源:origin: vadis365/TheErebus

@Override
public boolean canPlaceBlockAt(World world, BlockPos pos) {
  IBlockState state = world.getBlockState(pos.down());
  Block block = state.getBlock();
  if (block.canSustainPlant(state, world, pos.down(), EnumFacing.UP, this))
    return true;
  if (block == this)
    return true;
  else if (block != Blocks.GRASS && block != Blocks.DIRT)
    return false;
  return false;
}

代码示例来源:origin: vadis365/TheErebus

@Override
  public boolean canBlockStay(World world, BlockPos pos, IBlockState state) {
    IBlockState soil = world.getBlockState(pos.down());
    return (soil.getBlock().canSustainPlant(soil, world, pos.down(), net.minecraft.util.EnumFacing.UP, this));
  }
}

代码示例来源:origin: Ellpeck/ActuallyAdditions

@Override
public boolean canBlockStay(World world, BlockPos pos, IBlockState state){
  BlockPos offset = pos.down();
  IBlockState offsetState = world.getBlockState(offset);
  Block offsetBlock = offsetState.getBlock();
  return state.getValue(TYPE) == TheWildPlants.RICE ? offsetState.getMaterial() == Material.WATER : offsetBlock.canSustainPlant(offsetState, world, offset, EnumFacing.UP, this);
}

代码示例来源:origin: CoFH/ThermalFoundation

@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
  IBlockState soil = worldIn.getBlockState(pos.down());
  return super.canPlaceBlockAt(worldIn, pos) && soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
}

代码示例来源:origin: PenguinSquad/Harvest-Festival

@SuppressWarnings("unchecked")
private boolean canStay(World world, BlockPos pos) {
  CropData data = CropHelper.getCropDataAt(world, pos);
  if (data != null) {
    Crop crop = data.getCrop();
    if (crop.getGrowthHandler() != null) {
      IBlockState down = world.getBlockState(pos.down());
      return down.getBlock() == this || down.getBlock().canSustainPlant(down, world, pos, EnumFacing.UP, crop);
    }
  }
  return false;
}

代码示例来源:origin: PenguinSquad/Harvest-Festival

public boolean canBlockStay(World world, BlockPos pos, IBlockState state) {
  if (state.getBlock() == this) {
    IBlockState soil = world.getBlockState(pos.down());
    return soil.getBlock().canSustainPlant(soil, world, pos.down(), net.minecraft.util.EnumFacing.UP, this);
  }
  return canSustainBush(world.getBlockState(pos.down()));
}

代码示例来源:origin: vadis365/TheErebus

@Override
public boolean canBlockStay(World world, BlockPos pos, IBlockState state) {
  if (state.getBlock() == this) {
    IBlockState soil = world.getBlockState(pos.down());
    return soil.getBlock().canSustainPlant(soil, world, pos.down(), EnumFacing.UP, this);
  }
  return canSustainFlower(world.getBlockState(pos.down()));
}

代码示例来源:origin: CoFH/ThermalFoundation

public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
  if (state.getBlock() == this) //Forge: This function is called during world gen and placement, before this block is set, so if we are not 'here' then assume it's the pre-check.
  {
    IBlockState soil = worldIn.getBlockState(pos.down());
    return soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
  }
  return this.canSustain(worldIn.getBlockState(pos.down()).getBlock());
}

代码示例来源:origin: ForestryMC/ForestryMC

@Override
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
  if (pos.getY() >= 0 && pos.getY() < 256) {
    IBlockState iblockstate = worldIn.getBlockState(pos.down());
    return iblockstate.getBlock() == Blocks.MYCELIUM || (iblockstate.getBlock() == Blocks.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL || worldIn.getLight(pos) < 13 && iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this));
  } else {
    return false;
  }
}

代码示例来源:origin: JurassiCraftTeam/JurassiCraft2

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  ItemStack stack = player.getHeldItem(hand);
  IBlockState state = world.getBlockState(pos);
  if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, stack) && state.getBlock().canSustainPlant(state, world, pos, EnumFacing.UP, this) && world.isAirBlock(pos.up())) {
    world.setBlockState(pos.up(), this.sapling.getDefaultState());
    stack.shrink(1);
    return EnumActionResult.SUCCESS;
  } else {
    return EnumActionResult.FAIL;
  }
}

代码示例来源:origin: vadis365/TheErebus

@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  ItemStack stack = player.getHeldItem(hand);
  IBlockState state = worldIn.getBlockState(pos);
  if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, stack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up())) {
    worldIn.setBlockState(pos.up(), ModBlocks.PLANTED_FLOWER.getDefaultState().withProperty(BlockPlantedGiantFlower.TYPE, BlockPlantedGiantFlower.EnumFlowerType.values()[stack.getItemDamage()]), 11);
    stack.shrink(1);
    return EnumActionResult.SUCCESS;
  } else {
    return EnumActionResult.FAIL;
  }
}

相关文章

Block类方法