net.minecraft.block.BlockFarmland Java Examples

The following examples show how to use net.minecraft.block.BlockFarmland. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlantHelper.java    From EmergingTechnology with MIT License 6 votes vote down vote up
public static boolean isValidSoil(World world, BlockPos pos) {
    IBlockState soilBlockTarget = world.getBlockState(pos);
    Block block = soilBlockTarget.getBlock();

    if (block.isFertile(world, pos)) {
        return true;
    }

    if (block == ModBlocks.hydroponic) {
        if (soilBlockTarget.getActualState(world, pos).getValue(Hydroponic.HAS_WATER)) {
            return true;
        }
    }

    if (block == Blocks.FARMLAND) {
        if (soilBlockTarget.getActualState(world, pos).getValue(BlockFarmland.MOISTURE) > 0) {
            return true;
        }
    }

    return false;
}
 
Example #2
Source File: ItemBroom.java    From Sakura_mod with MIT License 5 votes vote down vote up
/**
    * Called when a Block is right-clicked with this Item
    */
@Override
   public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
   {
       ItemStack itemstack = player.getHeldItem(hand);

       if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack))
       {
           return EnumActionResult.FAIL;
       }
	IBlockState iblockstate = worldIn.getBlockState(pos);
	Block block = iblockstate.getBlock();

	if (facing != EnumFacing.DOWN && worldIn.getBlockState(pos.up()).getMaterial() == Material.AIR && ((worldIn.getBlockState(pos).getMaterial() == Material.GROUND||worldIn.getBlockState(pos).getMaterial() ==Material.GRASS) && !(block instanceof BlockFarmland||block instanceof BlockGrassPath)))
	{
	    IBlockState iblockstate1 = Blocks.GRASS_PATH.getDefaultState();
	    worldIn.playSound(player, pos, SoundEvents.BLOCK_GRASS_STEP, SoundCategory.BLOCKS, 1.2F, 1.2F);
	    worldIn.playSound(player, pos, SoundEvents.BLOCK_GRASS_PLACE, SoundCategory.BLOCKS, 1.2F, 1.2F);
	    if (!worldIn.isRemote)
	    {
	        worldIn.setBlockState(pos, iblockstate1, 11);
	        itemstack.damageItem(1, player);
	    }

	    return EnumActionResult.SUCCESS;
	}
	return EnumActionResult.PASS;
   }
 
Example #3
Source File: TileEntitySprinkler.java    From AgriCraft with MIT License 5 votes vote down vote up
/**
 * This method will search through a vertical column of positions, starting from the top. It
 * will stop searching any lower once it hits anything other than air or plants. Any plant found
 * has an independant chance for a growth tick. That percentage is controlled by
 * AgriCraftConfig. Farmland also ends the search, but it first has its moisture set to max (7)
 * if it isn't already. The lowest position is special: a plant this far away is not helped.
 * Only farmland is currently.
 */
private void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) {
    for (int targetY = highestY; targetY >= lowestY; targetY -= 1) {
        BlockPos target = new BlockPos(targetX, targetY, targetZ);
        IBlockState state = this.getWorld().getBlockState(target);
        Block block = state.getBlock();

        // Option A: Skip empty/air blocks.
        // TODO: Is there a way to use isSideSolid to ignore minor obstructions? (Farmland isn't solid.)
        if (block.isAir(state, this.getWorld(), target)) {
            continue;
        }

        // Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too.
        if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) {
            if (this.getRandom().nextInt(100) < AgriCraftConfig.sprinklerGrowthChance) {
                block.updateTick(this.getWorld(), target, state, this.getRandom());
            }
            continue;
        }

        // Option C: Dry farmland gets set as moist.
        if (block instanceof BlockFarmland) {
            if (state.getValue(BlockFarmland.MOISTURE) < 7) {
                this.getWorld().setBlockState(target, state.withProperty(BlockFarmland.MOISTURE, 7), 2);
            }
            break; // Explicitly expresses the intent to stop.
        }

        // Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop.
        break;
    }
}