Example usage for net.minecraftforge.common IPlantable getPlant

List of usage examples for net.minecraftforge.common IPlantable getPlant

Introduction

In this page you can find the example usage for net.minecraftforge.common IPlantable getPlant.

Prototype

BlockState getPlant(IBlockReader world, BlockPos pos);

Source Link

Usage

From source file:com.lothrazar.cyclicmagic.util.UtilPlantable.java

License:Open Source License

public static ItemStack tryPlantSeed(World world, BlockPos posForPlant, ItemStack stack) {
    BlockPos posSoil = posForPlant.down();
    if (stack != null && stack.getItem() instanceof IPlantable) {
        IPlantable seed = (IPlantable) stack.getItem();
        IBlockState crop = seed.getPlant(world, posForPlant);
        if (crop != null) {
            // mimic exactly what onItemUse.onItemUse is doing
            IBlockState state = world.getBlockState(posSoil);
            boolean canSustainPlant = state.getBlock().canSustainPlant(state, world, posSoil, EnumFacing.UP,
                    seed);// www  .jav  a  2  s  . c o  m
            if (canSustainPlant) {
                if (world.isAirBlock(posForPlant)) {
                    world.setBlockState(posForPlant, crop);
                    stack.shrink(1);
                    return stack;
                } else {
                    return stack;// ie, dont do super
                }
            }
        }
    }
    return null;
}

From source file:com.robrit.snad.common.block.BlockSnad.java

License:Open Source License

@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction,
        net.minecraftforge.common.IPlantable plantable) {
    BlockPos plantPos = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
    Block plant = plantable.getPlant(world, plantPos).getBlock();
    EnumPlantType plantType = plantable.getPlantType(world, plantPos);

    switch (plantType) {
    case Desert: {
        return true;
    }/*from w ww  .  j  a  v a 2 s  .co m*/
    case Water: {
        return world.getBlockState(pos).getBlock().getMaterial(world.getBlockState(pos)) == Material.WATER
                && world.getBlockState(pos) == getDefaultState();
    }
    case Beach: {
        return (world.getBlockState(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())).getBlock()
                .getMaterial(world
                        .getBlockState(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))) == Material.WATER
                || world.getBlockState(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())).getBlock()
                        .getMaterial(world.getBlockState(
                                new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))) == Material.WATER
                || world.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)).getBlock()
                        .getMaterial(world.getBlockState(
                                new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))) == Material.WATER
                || world.getBlockState(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)).getBlock()
                        .getMaterial(world.getBlockState(
                                new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ()))) == Material.WATER);
    }
    }

    return false;
}

From source file:de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.DefaultFarmerBehavior.java

private IBlockState getPlantablePlantFromStack(ItemStack stack, World world, BlockPos pos) {
    if (StackUtil.isValid(stack)) {
        IPlantable plantable = this.getPlantableFromStack(stack);
        if (plantable != null) {
            IBlockState state = plantable.getPlant(world, pos);
            if (state != null && state.getBlock() instanceof BlockCrops) {
                return state;
            }/*from  www  .j  a v a2 s  .c  om*/
        }
    }
    return null;
}